by holidayextras

holidayextras / jsonapi-server

A config driven NodeJS framework implementing json:api and GraphQL

465 Stars 117 Forks Last release: over 2 years ago (v4.2.0) MIT License 691 Commits 58 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Build Status Coverage Status npm version Dependencies Status


Greenkeeper badge

A config driven NodeJS framework implementing

. You define the resources, it provides the api.

Motivation / Justification / Rationale

This framework solves the challenges of json:api and GraphQL without coupling us to any one ORM solution. Every other module out there is either tightly coupled to a database implementation, tracking an old version of the json:api spec, or is merely a helper library for a small feature. If you're building an API and your use case only involves reading and writing to a data store... well count yourself lucky. For everyone else, this framework provides the flexibility to provide a complex API without being confined to any one technology.

A config driven approach to building an API enables: * Enforced json:api responses * Automatic GraphQL schema generation * Request validation * Payload validation * Automatic documentation generation * Automatic inclusions * Automatic routing * Automatic handling of relationships

Ultimately, the only things you as a user of this framework need to care about are: * What are my resources called * What properties do my resources have * For each resource, implement a

for: *
ing a resource *
ing a resource *
ing for many resources *
ing a specific resource *
ing a specific resource

We've created

s to automatically map our config over to database solutions help people get off the ground: * jsonapi-store-memoryhandler - an in-memory data store to enable rapid prototyping. This ships as a part of
and powers the core test suite. * jsonapi-handler-chain - a handler to chain custom behaviour around an existing handler. This ships as a part of
. More info can be found here * jsonapi-store-relationaldb - using
to support PostgreSQL, MySQL, MSSQL, MariaDB and SQLite. * jsonapi-store-mongodb - for MongoDB. * jsonapi-store-elasticsearch - for Elasticsearch. * jsonapi-store-dynamodb - !SIGNIFICANT WIP! for AWS DynamoDB.

We've also written a library to ease the consumption of a json:api compliant service, if GraphQL isn't your thing: * jsonapi-client - for NodeJS and Browsers

Full documentation

The tl;dr

You can have a complete json:api server providing a

resource with just this: ```javascript var jsonApi = require("jsonapi-server");

jsonApi.setConfig({ port: 16006, graphiql: true });

jsonApi.define({ resource: "photos", handlers: new jsonApi.MemoryHandler(), 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
and your
resources will be at
. The GraphiQL interface will be available at

Show me a full example!

Fire up an example

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 the JSON:API endpoints:
or, for GraphQL:
the example implementation can be found here

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.