MyAPI is a simple REST API designed for managing customer data. This document serves as a guide to make HTTP requests to our API.
Front-end portion has been compressed into the build module. Thus, in order to run the application, simply run npm start. The front-end will be rendered and the back-end will be connected to the application.
The base URL for all endpoints is:
Endpoints Below are the available endpoints:
GET / GET /api/persons/:id POST /api/persons DELETE /api/persons/:id GET /api/persons GET /info
This is the home route and it will return an HTML response.
This endpoint retrieves a person with a given id.
Parameters:
id - This is the id of the person.
Example request:
curl http://localhost:3001/api/persons/1
This endpoint creates a new person.
Body Parameters:
name - The name of the person. important - A boolean indicating the importance status of the person. (Optional) weight - The weight of the person. age - The age of the person. Example request:
curl -X POST -H "Content-Type: application/json" -d '{"name": "John Doe", "important": true, "weight": 70, "age": 30}' http://localhost:3001/api/persons
This endpoint deletes a person with a given id.
Parameters:
id - This is the id of the person.
Example request:
curl -X DELETE http://localhost:3001/api/persons/1
This endpoint retrieves all persons.
Example request:
curl http://localhost:3001/api/persons
This endpoint retrieves the total number of persons and current server time.
Example request:
curl http://localhost:3001/info Errors The API will return the following error types when requests fail:
400: Bad Request – There is missing or invalid information in your request. 404: Not Found – The requested resource could not be found. 500: Internal Server Error – We had a problem with our server. Please try again later. Setup To run the server locally:
Clone the repository Install the dependencies with npm install Start the server with npm start