Skip to main content

HTTP Framework Compatibility

Podium is HTTP framework agnostic with first class support for Express. In practise this means that core Podium works with the standard http.Server module in Node.js but the core modules also come with Express compatible middleware methods for ease of use.

Due to the fact that Podium is built for usage with the http.Server module in Node.js, it's pretty straight forward to get Podium to work with most HTTP frameworks. The most common way to support different HTTP framework is through plugins.

Hapi and Fastify are both HTTP frameworks that the Podium team support by maintaining plugins for each. There are also user land plugins for other HTTP frameworks.

Using Podium together with Hapi or Fastify requires that the plugin is handed an instance of the appropriate Podium module.

Example of setting up a podlet server in all HTTP frameworks supported by the Podium team:

import express from 'express';
import Podlet from '@podium/podlet';

const app = express();

const podlet = new Podlet({
name: 'myPodlet',
version: '1.0.0',
pathname: '/',
development: true,
});

app.use(podlet.middleware());

app.get(podlet.content(), (req, res) => {
if (res.locals.podium.context.locale === 'nb-NO') {
return res.status(200).podiumSend('<h2>Hei verden</h2>');
}
res.status(200).podiumSend(`<h2>Hello world</h2>`);
});

app.get(podlet.manifest(), (req, res) => {
res.status(200).json(podlet);
});

app.listen(7100);