Code Monkey home page Code Monkey logo

netiam

Build Status Dependencies npm version

A pure REST library

This REST API library addresses some issues we had with API designs in our projects. It does not claim to provide a full featured solution and to be honest, it might never will. Nevertheless, someone might find this library useful. It works as connect middleware and you should be able to use it with any compatible infrastructure (e.g. express).

TOC

Get it

npm i -S netiam

Plugins

What can it do for you

  • Authentication (with passportjs and OAuth 2.0)
  • Authorization (through ACLs)
  • Relationships(on resource level)
  • Query language (OData filter expressions)
  • Completely stateless (except cookie based sessions for authentication in browser apps)
  • Support for the JSONAPI specification
  • Auto response format detection
  • Graph representation and rendering (as SVG)
  • Extensible with plugins

Getting started

Creates a single route, using the data plugin to add some data and returns everything as JSON.

import express from 'express'
import http from 'http'
import api from 'netiam'

const app = express()
const server = http.createServer(app)

app.get(
  '/users'
  api()
    .data({'Hello': 'World!'})
    .json()
)

server.listen(3000)

How it works

The core idea is to have a stack of plugins executed in an asynchronous way.

const path = api()
  .rest({})
  .json()

app.get('/foo', path)

Plugin example

export default function data(data) {
  return function(req, res) {
    res.body = data;
  }
}

Example

app.get(
  '/users',
  api()
    .auth()
    .rest()
    .acl.res()
    .jsonapi({})
)

Error handling

You do not need to handle common API errors on your own. The library responds to the client at least with a proper HTTP status code (e.g. 404 for document not found) automatically.

Tests

Using mocha with should for tests and istanbul to check coverage.

npm test

Supported by

License

MIT License

netiam's Projects

cli icon cli

The netiam CLI tool

demo icon demo

This is the official netiam demo.

oauth icon oauth

An implementation of the OAuth 2.0 authorization framework

query icon query

Declarative and expressive database queries.

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.