- Clone the repo api-testing
- Go to the root directory of the project from your terminal
- Run
docker-compose up. You should see something like this
- Open mysql workbench
- Click on create new connection
- Enter the details as shown in below screenshot with user as
user123and password aspassword1234
- Click on test connection, the connection to the database should be successful.
- Double click on the newly created database
- Click on create new query session
- Run the below select query, should see a record on the table
SELECT * FROM employee.EmployeeDetails;
Let's say we want to find the details of the employees whose state is NJ
For this we need to pass the state to the request, that's where request parameters will come into play.
RequestUrl : http://localhost:7174/api/employee/ByState
RequestParams : state
HttpMethod : GET
In order create, update or delete employee details, we need to get a bearer token and add to the header.
This would also help you to understand how we can test an authorization to the endpoint.
To get the bearer token , hit the endpoint http://localhost:7174/api/auth with the below request body
{
"username" : "random@gmail.com",
"password" : "strongpassword"
}
Add the token as bearer header for the POST/PUT/DELETE endpoint as shown below
- Create a GET srequest to read the details of EmployeeId
1
RequestUrl : http://127.0.0.1:7174/api/employee/1
HttpMethod : GET
Refer to authorization section how to authorize endpoint
- Create a POST request to create new employee details, see the below screenshot for example
RequestUrl : http://127.0.0.1:7174/api/employee
HttpMethod: POST
RequestBody:
{
"EmployeeID": 2,
"FirstName": "James",
"LastName": "sad",
"Age": 30,
"State": "MI"
}
Refer to authorization section how to authorize endpoint
Let's update the State of the newly created employee to IL. For this we need to create a PUT request
RequestUrl : http://127.0.0.1:7174/api/employee/2`
HttpMethod: PUT
RequestBody:
{
"EmployeeID": 2,
"FirstName": "James",
"LastName": "sad",
"Age": 30,
"State": "IL"
}
Refer to authorization section how to authorize endpoint
Let's update employee 2 again, changing their state from IL to NY. For this we will be using a PATCH request.
You might be wondering, what's the difference between PUT and PATCH? In a PATCH request, we do not send the entire request body details. We only send what is changing.
RequestUrl : http://127.0.0.1:7174/api/employee/2
HttpMethod: PATCH
request Body:
{
"State": "NY"
}
Refer to authorization section how to authorize endpoint
We can incur by the name, if you want to delete a record then we use DELETE request.
RequestUrl : http://127.0.0.1:7174/api/employee/2
HttpMethod: DELETE