š”Ā Ā Use cases
Some examples of dev. projects you can build more easily thanks to this toolset.
Creating a Back-for-Front for your app.
This was the main incentive for making Astro OpenAPI.
Being able to federated various API sources, pre-process them, while
adding some custom logic (e.g: sessions, guards, user input validationā¦).
Typically (but not always), your Astro SSR instance is stateless, running on serverless short-lived functions.
Youāre sourcing data from external APIs provider, with a mix of in-house micro-services,
SaaS, you name it.
While adding a layer of security, youāll want to structure all that data youāre consuming server side, to finally serve an optimized version to your client browser runtime.
This is called a āBack-For-Frontā, or BFF (not to confound with Best-Friend-Forever š¤š¤).
In order to do that, you could leverage external references to:
- Just kind-of proxying API calls with API implementation mirroring
- Source just the bit of definitions you need (most likely the entities schemas)
- Or make a full facade, without any upstream reference
Those three levels of integration can sit well within you application context (e.g: auth.).
Making your type-safe content server
Operations can be read-only.
With a nice query language you could integrate,
for example the excellent Mingo, an agnostic MongoDB-like query implementation.
const homeworks = app.queryContent({
type: 'homework',
score: { $gte: 50 },
});
const homeworks = app.queryContent([
{ $match: { type: 'homework' } },
{
$group: {
_id: '$student_id',
score: { $min: '$score' },
},
},
{ $sort: { _id: 1, score: 1 } },
]);
DX-wise, pairing with remark-lint-frontmatter-schema, you can re-use the same schemas for validating redacted Markdown frontmatter, or even pure YAML (with endpoints validation alone).
This code can never land on any server, for example if youāre using this for dev. / pre-processing a static build (an idea for an Astro integration? š).
Or maybe you WANT to make it a live content API.
If so, you can source from a backend like Git(Hub), YJS, databasesā¦
Inspirations: nuxt/content, astro-contentā¦