Skip to content

sqass/api-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Software needed

  1. postman
  2. docker
  3. my sql

Running the application

  1. Clone the repo api-testing
  2. Go to the root directory of the project from your terminal
  3. Run docker-compose up . You should see something like this image
  4. Open mysql workbench
  5. Click on create new connection
  6. Enter the details as shown in below screenshot with user as user123 and password as password1234
image
  1. Click on test connection, the connection to the database should be successful.
  2. Double click on the newly created database
  3. Click on create new query session
  4. Run the below select query, should see a record on the table
SELECT * FROM employee.EmployeeDetails;
image

Testing the api using postman

What are Request Parameters in postman ?

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

image

Authorization

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"
}
image

Add the token as bearer header for the POST/PUT/DELETE endpoint as shown below

image

Create your first GET request

  • Create a GET srequest to read the details of EmployeeId 1

RequestUrl : http://127.0.0.1:7174/api/employee/1

HttpMethod : GET

image

Create your first POST request

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"
}
image

Create your first PUT request

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"
}
image

Create your first PATCH request

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"
}
image

Create your first DELETE request

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

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors