Socket
Book a DemoInstallSign in
Socket

api-i

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-i

Create REST API

10.1.1
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

API

FAQs

Package last updated on 06 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.