A simple array based REST service for address book apps
Installing:
npm install --save addressbook-rest
Using:
Create a file server.js under the project folder (along side package.json)
Simplest code to start the REST service at port 8080 with a base url "/api/":
require("addressbook-rest").start();
Customization of port and base url prefix:
var server = require("addressbook-rest"); var port = 9999; var baseUrl = "api"; server.start({ port, baseUrl }, ()=>{ console.log(`Server is running at http://localhost:${port}/${baseUrl}/contacts`) });
Accessing:
Visit http://localhost:9999/api/contacts using a browser (or a REST client)
- GET http://localhost:9999/api/contacts --> all contacts
- GET http://localhost:9999/api/contacts/3 --> specific contact by id
- POST http://localhost:9999/api/contacts --> add a new contact sent via payload
- PUT http://localhost:9999/api/contacts/3 --> updates contact with id 3, data sent as payload
- DELETE http://localhost:9999/api/contacts/3 --> deletes contact with id 3