jsonapi-server
is a fully featured NodeJS server implementation of json:api
. You provide the resources, we provide the api.
- Configuring jsonapi-server
- Defining Resources
- Foreign Key Relations
- Creating Handlers
- Post Processing Examples
You can have a complete json:api server providing a photos
resource with just this:
var jsonApi = require("jsonapi-server");
jsonApi.setConfig({
base: "rest",
port: 16006,
});
jsonApi.define({
resource: "photos",
handlers: jsonApi.mockHandlers,
attributes: {
title: jsonApi.Joi.string()
url: jsonApi.Joi.string().uri()
height: jsonApi.Joi.number().min(1).max(10000).precision(0)
width: jsonApi.Joi.number().min(1).max(10000).precision(0)
}
});
jsonApi.start();
Your new API will be alive at http://localhost:16006/rest/
and your photos
resources will be at http://localhost:16006/rest/photos
.
Fire up an example json:api
server using the resources mentioned in the official spec via:
git clone https://github.com/holidayextras/jsonapi-server.git
npm install
npm start
then browse to
http://localhost:16006/rest/photos
the example implementation can be found here