api-i

10.1.1 • Public • Published

NPM version NPM downloads MIT License Build Status: Linux Build Status: Windows Coverage Status

API-I

v.10.1.1

Example

npm i -S api-i

npm i -S sqlite3

example.js

const Api = require('api-i');
const config = {
  server: {
    port: 8877,
  },
  db: {
    client: 'sqlite3',
    connection: ':memory:',
  },
  updateGet: (...raw) => ({raw}),
};

const api = new Api(config);

const updateGet = (...data) => ({ data});

(async () => {
  await api.model('books', { name: 'string' }, { links: 'writers', openMethods: ['GET', 'POST', 'DELETE'], updateGet });
  await api.model('writers', { name: 'string', birth: { type: 'date', required: true } });

  await api.start();

  await api.initData('books', [
    {name: "Alice's Adventures in Wonderland"},
    {name: "Moby-Dick; or, The Whale"},
  ])
})();

GET request example

curl localhost:8877/books

{"data":[[{"id":1,"created_at":null,"updated_at":null,"name":"Alice's Adventures in Wonderland"},{"id":2,"created_at":null,"updated_at":null,"name":"Moby-Dick; or, The Whale"}]]}

GET by id

curl localhost:8877/books/2

{"id":2,"created_at":null,"updated_at":null,"name":"Moby-Dick; or, The Whale"}

POST request example

curl -X POST -d '{"name":"Les Trois Mousquetaires"}' --header "Content-Type: application/json" localhost:8877/books

{"id":3}

DELETE request example

curl -X DELETE localhost:8877/books/2

Created by

Dimitry Ivanov 2@ivanoff.org.ua # curl -A cv ivanoff.org.ua

Package Sidebar

Install

npm i api-i

Weekly Downloads

1

Version

10.1.1

License

MIT

Unpacked Size

95.8 kB

Total Files

33

Last publish

Collaborators

  • ivanoff