Git Product home page Git Product logo

jsonapi-server's Introduction

Build Status Coverage Status npm version Dependencies Status

jsonapi-server

Greenkeeper badge

A config driven NodeJS framework implementing json:api and GraphQL. 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 handler for:
    • createing a resource
    • deleteing a resource
    • searching for many resources
    • finding a specific resource
    • updateing a specific resource

We've created handlers to automatically map our config over to database solutions help people get off the ground:

We've also written a library to ease the consumption of a json:api compliant service, if GraphQL isn't your thing:

Full documentation

The tl;dr

You can have a complete json:api server providing a photos resource with just this:

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 http://localhost:16006/ and your photos resources will be at http://localhost:16006/photos. The GraphiQL interface will be available at http://localhost:16006/.

Show me a full example!

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 the JSON:API endpoints:

http://localhost:16006/rest/photos

or, for GraphQL:

http://localhost:16006/rest/

the example implementation can be found here

jsonapi-server's People

Contributors

theninj4 avatar pmcnr-hx avatar paparomeo avatar joseph-norman avatar greenkeeper[bot] avatar greenkeeperio-bot avatar st3xupery avatar wolfgang42 avatar olivierchatry avatar slickmb avatar championswimmer avatar jokeyrhyme avatar adamlc avatar alunyov avatar brycecicada avatar oliversalzburg avatar richardschneider avatar duncanfenning avatar aledalgrande avatar dlras2 avatar harryjubb avatar jamesplease avatar jstafford avatar jpinnix avatar maxschmeling avatar nihgwu avatar

Watchers

James Cloos avatar jostein lien avatar  avatar Jon Babsvik avatar Olav Sylthe avatar  avatar Christian Pujol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.