Template rendering #315
-
Recently learned about Marblejs and would really love to use it, but my work is not usually about building REST APIs. I know Marblejs is geared towards APIs, but was wondering if there's a solution on rendering templates. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @JoshPolaris, export const foo$ = r.pipe(
r.matchPath('/foo'),
r.matchType('GET'),
r.useEffect((req$, ctx) => {
// lets assume that there is an already registered renderer instance in the context,
// eg. the previously mentioned mustache.js
const htmlRenderer = useContext(SomeHtmlRendererToken)(ctx.ask);
return req$.pipe(
mergeMap(flow(
extractParameters,
htmlRenderer.render)),
map(body => ({
status: HttpStatus.OK,
headers: { 'Content-Type': 'text/html' },
body,
});
);
}),
); update: const getFile$ = r.pipe(
r.matchPath('/static/:dir*'),
r.matchType('GET'),
r.useEffect(req$ => req$.pipe(
validateRequest,
map(req => req.params.dir),
mergeMap(readFile),
map(body => ({ body })),
)),
); |
Beta Was this translation helpful? Give feedback.
Hi @JoshPolaris,
Could you describe more the use case in which you would like to use server side rendering?
Marble.js doesn't have any built-in mechanism (module/package) for rendering templates but it doesn't mean that it is impossible. It is just a typical HTTP flow. Generally speaking it is a matter of integrating a specific template rendering engine, like eg. mustache.js or something else, even React or other library. Nothing too complex, really. :)