REST API Endpoints

REST API Endpoints

In the last lesson, you opened http://localhost:3000/users in your browser and received a response from the backend server that said "Respond with a resource".

When you enter a URL into your browser's navigation bar, it triggers an HTTP GET request to the server specified at the beginning part of the URL. In this case, the local machine, localhost on port 3000.

Since we asked for /users and since the request was a GET request, the Express middleware routed the request to the get handler code in /backend/routes/users.js.

Handler code that responds to an HTTP request in a backend application is known as an endpoint. An endpoint is the end destination of a network request which is responsible for replying back to the caller with a resource, such as a file or a JSON payload.

Any given route can have different endpoints that handle the different HTTP methods such as GET. Let's review the most common HTTP methods: GET, POST, PUT and DELETE.

HTTP GET Requests#

GET requests are used for fetching a resource or a list of resources from a server. GET requests should not modify data. For example, this would be bad practice for a GET request:

The above URL has query parameters that provide instructions to the server. GET requests do not have a body and all information is conveyed to the server via query parameters and the route itself.

HTTP POST Requests#

POST requests are commonly used for creating a resource. A POST request can have query parameters but also can have a body, where additional data is sent to the server.

Here is an example of a POST request with a JSON body:

Usually the server's response to a POST request should contain the unique ID of the newly created resource. Here's an example response to the above POST:



Start a new discussion. All notification go to the author.