
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
openapi-backend
Advanced tools
Tools for building API backends with the OpenAPI standard previously known as Swagger
(Currently only OpenAPI v3.0.0+ is supported)
Full example projects included in the repo
npm install --save openapi-backend
import OpenAPIBackend from 'openapi-backend';
const api = new OpenAPIBackend({
definition: {
openapi: '3.0.2',
info: {
title: 'My API',
version: '1.0.0',
},
paths: {
'/pets': {
get: {
operationId: 'getPets',
responses: {
200: { description: 'ok' },
},
},
},
'/pets/{id}': {
get: {
operationId: 'getPetById',
parameters: [
{
name: 'id',
in: 'path',
required: true,
schema: {
type: 'integer',
},
},
],
responses: {
200: { description: 'ok' },
},
},
},
},
},
handlers: {
// your platform specific request handlers here
getPets: async (req) => ({ status: 200, body: 'ok' }),
getPetById: async (req) => ({ status: 200, body: 'ok' }),
notFound: async (req) => ({ status: 404, body: 'not found' }),
validationFail: async (err, req) => ({ status: 400, body: JSON.stringify({ err }) }),
},
});
// initalize the backend
api.init();
import express from 'express';
const app = express();
app.use((req, res) => api.handleRequest(req, req, res));
app.listen(9000);
import Hapi from 'hapi';
const server = new Hapi.Server({ host: '0.0.0.0', port: 9000 });
server.route({
method: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
path: '/{path*}',
handler: (req, h) =>
api.handleRequest(
{
method: req.method,
path: req.path,
body: req.payload,
query: req.query,
headers: req.headers,
},
req,
h,
),
});
server.start();
// API Gateway Proxy handler
module.exports.handler = (event, context) =>
api.handleRequest(
{
method: event.httpMethod,
path: event.path,
query: event.queryStringParameters,
body: event.body,
headers: event.headers,
},
event,
context,
);
module.exports = (context, req) =>
api.handleRequest(
{
method: req.httpMethod,
path: req.params.path,
query: req.queryStringParameters,
body: req.body,
headers: req.headers,
},
context,
req,
);
OpenAPI Backend is Free and Open Source Software. Issues and pull requests are more than welcome!
FAQs
Build, Validate, Route, Authenticate and Mock using OpenAPI definitions. Framework-agnostic
The npm package openapi-backend receives a total of 37,959 weekly downloads. As such, openapi-backend popularity was classified as popular.
We found that openapi-backend demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.