Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

  • 7.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5K
increased by2457.73%
Maintainers
1
Weekly downloads
 
Created
Source

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

API-I

v.7.0.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

FAQs

Package last updated on 23 Jul 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc