In this tutorial, you learn the operations to call to get a user by the last_name
property in a user
resource.
This tutorial should take around 10 minutes to complete.
You need to use the GET
method to retrieve the details of a user
resource in the service using the last_name
property.
To get a user by last name:
Make sure your local service is running, or start it by using this command, if it’s not.
cd <your-github-workspace>/to-do-service/api
json-server -w to-do-db-source.json
/users
Content-Type: application/json
Query Parameters:
You can change the value of the last_name
property to the last name of the user whose details you want to retrieve.
{
?last_name=Martinez
}
The full request should look like:
{
GET {base_url}/users?last_name=Martinez
}
Watch for the response body, which should return the user
resource with the last_name
property in your GET
request.
{
"last_name": "Martinez",
"first_name": "Marty",
"email": "m.martinez@example.com",
"id": 3
}
After doing this tutorial in Postman, you might like to repeat it in your favorite programming language. To do this, adapt the values from the tutorial to the properties and arguments that the language uses to make REST API calls.
Now that you know how to get a user by their last name, you can branch out by using other properties in the user
resource in your GET
request to retrieve the details of a specific user.
To narrow down the number of user
resources in your response, include more than one property in your request.
You can refine your GET
requests by viewing the other read operations for the user
resource: