Question: The objective of this task is to write an API with one GET endpoint. Requirements You are required to write an API with Express that

The objective of this task is to write an API with one GET endpoint.
Requirements
You are required to write an API with Express that will contain the following endpoint:
GET /users
endpoint should return status code 200 on successful request;
endpoint should return the data taken from the mocked-up database using the provided helper function getUsers. This function returns an array of user objects containing id (number), name (string) and role (string). An example array might appear as follows:
"id": 1,
"name": "John",
"role": "admin"
}
"id": 2,
"name" : "Juan",
"role": "developer"
endpoint should accept a query parameter name which will contain a string;
when parameter name is provided, all users whose name property is equal to the name query parameter must be returned (it may happen that there will be more than one match). If no users with the given name are found, an empty array must be returned.
Hints
Your solution will be evaluated based on its correctness; performance and coding style will not be assessed.
You can assume that the 1d, name and role properties of the users returned from the database are present and of the correct types. You do not have to verify them.
You do not have to take care of unsuccessful requests; the response is always successful and the status code must equal 200.
Available packages/libraries
Express: 4.17.1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!