Address Book REST API
REST API for an address book using Node.js, ElasticSearch and Express.js.
Getting Started
- Make sure you have
npm
installed on your machine. You can install it from here. - Clone the repository locally and navigate into it.
- Run
npm install
from your shell to install all the dependencies which are mentioned in thepackage.json
file. - Download and install ElasticSearch on your machine from here.
Running Locally
- Once all the dependencies are installed, you can run
node server.js
from the root of the repository directory to run the server. The server can be accessed athttp://localhost:8080
. - To check if your ElasticSearch is running properly, run
curl 'http://localhost:9200/?pretty'
from your shell and it should give you a JSON response.
API Endpoints
- POST - Add a new contact to your book
$ curl -H "Content-Type: application/json" -d "{\"name\": \"jon\", \"lastname\": \"doe\", \"email\": \"k@example.com\", \"phone\": \"2455663456\", \"address\": \"heaven\"}" -X POST http://localhost:8080/contact/
- GET one - Get a user using their name in the URL
$ curl -X GET http://localhost:8080/contact/jon
- GET all - Get all users using additional parameters
$ curl -X GET "http://localhost:8080/?pageSize={10}&page={1}&query={\"name\": \"jon\"}"
Here, we have pageSize
(number of results that are allowed back), page
(get specific page numbers), and query
which is a Query String Query as defined by Elasticsearch that you can pass directly in the Elasticsearch call.
- UPDATE - Update an existing contact by passing their name
$ curl -H "Content-Type: application/json" -d "{\"new_name\": \"John\", \"new_phone\": \"1234567890\"}" -X PUT http://localhost:8080/contact/jon
- DELETE - Delete an existing contact by passing their name
$ curl -X DELETE "http://localhost:8080/contact/John"
Testing
The testing was carried out using Mocha and Chai.