/node-books-api

This project was created as an example of "How to Create a Nodejs API" for educational porposes.

Primary LanguageJavaScript

NODE-BOOKS-API

This project was created as an example of "How to Create a Nodejs API" for educational porposes.

Requirements

Start Server

To install all dependencies, you must run the following command:

$ yarn

To run the application:

$ yarn start

To start server into a docker container:

$ docker build -t somadevs/node-books-api .
$ docker run --name node-books-api -p 3000:3000 -d somadevs/node-books-api

Configure the connection string into: ./src/config.json
As an suggestion, use a database on the mLab platform: https://mlab.com/


Endpoints

Authors

  • GET: /api/authors
// GET http://localhost:3000/api/authors
// RESPONSE (STATUS: 200)
[
  {
    name: String,
    createAt: Date,
    id: String
  }
];
  • GET: /api/authors/:id
// GET http://localhost:3000/api/authors/:id
// RESPONSE (STATUS: 200)
{
"name": String,
"createAt": Date,
"id": String
}
  • POST: /api/authors/
// POST http://localhost:3000/api/authors
// REQUEST (BODY: JSON)
{
"name": String
}

// RESPONSE (STATUS: 201)
{
"name": String,
"createAt": Date,
"id": String
}
  • PUT: /api/authors/:id
// PUT http://localhost:3000/api/authors/:id
// REQUEST (BODY: JSON)
{
"name": String
}

// RESPONSE (STATUS: 204)
  • DELETE: /api/authors/:id
// DELETE http://localhost:3000/api/authors/:id
// RESPONSE (STATUS: 204)

Books

  • GET: /api/books
// GET http://localhost:3000/api/books
// RESPONSE (STATUS: 200)
[
  {
    name: String,
    year: Number,
    author: {
      name: String,
      createAt: Date,
      id: String
    },
    createAt: Date,
    id: String
  }
];
  • GET: /api/books/:id
// GET http://localhost:3000/api/books/:id
// RESPONSE (STATUS: 200)
{
 "name": String,
 "year": Number,
 "author": {
   "name": String,
   "createAt": Date,
   "id": String
 },
 "createAt": Date,
 "id": String
}
  • POST: /api/books/
// POST http://localhost:3000/api/books/:id
// REQUEST (BODY: JSON)
 {
   "name": String,
   "year": Number,
   "author": String
 }

 // RESPONSE (STATUS: 201)
 {
   "name": String,
   "year": Number,
   "author": {
     "name": String,
     "createAt": Date,
     "id": String
   },
   "createAt": Date,
   "id": String
 }
  • PUT: /api/books/:id
// PUT http://localhost:3000/api/books/:id
// REQUEST (BODY: JSON)
{
  "name": String,
  "year": Number,
  "author": String
}

// RESPONSE (STATUS: 204)
  • DELETE: /api/books/:id
// DELETE http://localhost:3000/api/books/:id
// RESPONSE (STATUS: 204)

MEDIUM: https://medium.com/@thiagodesouza.io
E-MAIL: email@thiagodesouza.com