HTTP Plus Files Bundle
Combine a local YAML config file with an HTTP fetch and emit both a JSON bundle and route metadata.
Source
examples/http-plus-files-bundle/input.yaml
site:
name: Rank Launchpad
themeColor: tide
navItems:
- Overview
- Docs
- Pricing
landing:
heroTitle: Ship configuration as code
featuredArticleSlug: rank-http-fetch
examples/http-plus-files-bundle/main.rank
/// Combines a local YAML config file with an HTTP fetch and emits a bundle.
/// Shows File::Read and HTTP::Fetch working together in one program.
use std::Emit
use std::File
use std::HTTP
use std::Path
InputConfig = Object {
site: Object {
name: string,
themeColor: string,
navItems: [string],
},
landing: Object {
heroTitle: string,
featuredArticleSlug: string,
},
}
Author = Object {
id: string,
name: string,
avatar: string,
email: string,
}
Article = Object {
slug: string,
title: string,
subtitle: string,
image: string,
author: Author,
dateCreated: string,
content: string,
}
input_result = File::Read<InputConfig> {
path: Path::join([`input.yaml`]),
format: `yaml`,
}
input = input_result.body
article_result = HTTP::Fetch<Article> {
url: `https://lorem-api.com/api/article/rank-http-fetch`,
method: `GET`,
headers: {
Accept: `application/json`,
},
cacheKey: `http-plus-files-bundle-rank-http-fetch-v1`,
}
article = article_result.body
bundle = {
site: {
name: input.site.name,
themeColor: input.site.themeColor,
heroTitle: input.landing.heroTitle,
navItems: input.site.navItems,
},
featuredArticle: {
slug: article.slug,
title: article.title,
subtitle: article.subtitle,
author: article.author.name,
publishedAt: article.dateCreated,
},
source: {
articleCacheKey: article_result.ctx.cacheKey,
status: article_result.ctx.status,
},
}
routes = {
siteName: input.site.name,
routes: [
{
path: `/`,
title: input.landing.heroTitle,
},
{
path: `/articles/${article.slug}`,
title: article.title,
},
],
}
pub main = || Emit::manifest({
entries: [
{
path: Path::join([`bundle`, `site-bundle.json`]),
format: `json`,
value: bundle,
},
{
path: Path::join([`bundle`, `routes.yaml`]),
format: `yaml`,
value: routes,
},
]
})
Output
Running the example with --file-root writes:
bundle/site-bundle.jsonbundle/routes.yaml
Run it
npm run rank -- examples/http-plus-files-bundle --file-root out/http-plus-files-bundle
Key concepts
File::Readcan load local structured input whileHTTP::Fetchcontributes remote typed data in the same program.cacheKeykeeps the HTTP side deterministic for repeated evaluations.- Response metadata from
response.ctxcan flow directly into emitted artifacts.