filmov
tv
Manual API Testing with Postman, and importing to code to C# (RestSharp) and with Specflow
Показать описание
What is an API?
API stands for Application Programming Interface. Talking in technical terms an API is a set of procedures, functions, and other points of access which an application, an operating system, a library etc., makes available to programmers in order to allow it to interact with other software.
How Does a REST Request Work?
Before diving into API testing, you’ll need to learn a few of the basics. An API is made up of a set of REST requests. These are the requests made to an application server that retrieve, delete, or manipulate data in an application’s database.
A REST request is made up of the following parts:
• An HTTP verb that describes what action should be taken
• A Uniform Resource Locator (URL) that defines the location of the request
• HTTP headers that provide information to the server about the request
• A request body that provides further details for the request (this can sometimes be empty)
Here are the most common HTTP verbs:
• A GET request fetches a record from a database
• A POST request adds a new record to a database
• A PUT request replaces a record with a new one
• A PATCH request replaces part of a record with new information
• A DELETE request removes a record from a database
HTTP headers can provide information to the server such as:
• The Host: the domain and port number of the user making the request
• Authorization: the credentials of the user making the request
• The Content-Type: the format of the information provided in the body of the request
The request body is used when making POST, PUT, or PATCH requests. The body specifies exactly what information should be added to the database. It is usually in JavaScript Object Notation (JSON) or Extensible Markup Language (XML) format.
Here is an example of what a JSON request body might look like for doing a POST request that adds a customer to a database:
{
“firstName”: “John”,
“lastName”: “Smith”,
}
What Is Included in the Response to a REST Request?
The response to a REST request is the information that the server sends back after it has received and processed the request.
It will include
HTTP headers that describe the response,
a response code that describes the success or failure of the response, and
a response body that includes requested or relevant information (this can sometimes be empty).
The HTTP headers in the response provide information to the requesting party such as:
• Access-Control headers: tell the requester what types of requests and headers will be allowed
• The Content-Type: the format of the information returned in the response
• The Server: the name of the server that responded to the request
Response codes are three-digit codes used to describe the result of the REST request. The most common response codes come in one of these three categories:
• 200-level responses indicate that the request was received, understood, and processed
• 400-level responses indicate that the request was received, but that there was an error from the client
• 500-level responses indicate that there was some sort of server error
HTTP Status codes
Code Title Description
200 OK The request was successful.
201 Created The resource was successfully created.
202 Async created The resource was asynchronously created
400 Bad request Bad request
401 Unauthorized Your API key is invalid.
402 Over quota Over plan quota on this endpoint.
404 Not found The resource does not exist.
422 Validation error A validation error occurred.
50X Internal Server Error
Step 1:
• Click the “Try it out” button
• Put the number 1 in the field marked “ID of pet to return”
• Click the “Execute” button
• Scroll down to the Response body and verify that a record for a pet has been returned (if a record was not returned, try the request again with a different ID in the “ID of pet to return” field)
Step 2:
Step 3:
• Launch Postman
• In the top middle of the screen, verify that you see the word “GET” in the HTTP verb dropdown
• Click the “Send” button, and verify that you receive a response code of 200 OK, and that the response body contains the record for the pet
API stands for Application Programming Interface. Talking in technical terms an API is a set of procedures, functions, and other points of access which an application, an operating system, a library etc., makes available to programmers in order to allow it to interact with other software.
How Does a REST Request Work?
Before diving into API testing, you’ll need to learn a few of the basics. An API is made up of a set of REST requests. These are the requests made to an application server that retrieve, delete, or manipulate data in an application’s database.
A REST request is made up of the following parts:
• An HTTP verb that describes what action should be taken
• A Uniform Resource Locator (URL) that defines the location of the request
• HTTP headers that provide information to the server about the request
• A request body that provides further details for the request (this can sometimes be empty)
Here are the most common HTTP verbs:
• A GET request fetches a record from a database
• A POST request adds a new record to a database
• A PUT request replaces a record with a new one
• A PATCH request replaces part of a record with new information
• A DELETE request removes a record from a database
HTTP headers can provide information to the server such as:
• The Host: the domain and port number of the user making the request
• Authorization: the credentials of the user making the request
• The Content-Type: the format of the information provided in the body of the request
The request body is used when making POST, PUT, or PATCH requests. The body specifies exactly what information should be added to the database. It is usually in JavaScript Object Notation (JSON) or Extensible Markup Language (XML) format.
Here is an example of what a JSON request body might look like for doing a POST request that adds a customer to a database:
{
“firstName”: “John”,
“lastName”: “Smith”,
}
What Is Included in the Response to a REST Request?
The response to a REST request is the information that the server sends back after it has received and processed the request.
It will include
HTTP headers that describe the response,
a response code that describes the success or failure of the response, and
a response body that includes requested or relevant information (this can sometimes be empty).
The HTTP headers in the response provide information to the requesting party such as:
• Access-Control headers: tell the requester what types of requests and headers will be allowed
• The Content-Type: the format of the information returned in the response
• The Server: the name of the server that responded to the request
Response codes are three-digit codes used to describe the result of the REST request. The most common response codes come in one of these three categories:
• 200-level responses indicate that the request was received, understood, and processed
• 400-level responses indicate that the request was received, but that there was an error from the client
• 500-level responses indicate that there was some sort of server error
HTTP Status codes
Code Title Description
200 OK The request was successful.
201 Created The resource was successfully created.
202 Async created The resource was asynchronously created
400 Bad request Bad request
401 Unauthorized Your API key is invalid.
402 Over quota Over plan quota on this endpoint.
404 Not found The resource does not exist.
422 Validation error A validation error occurred.
50X Internal Server Error
Step 1:
• Click the “Try it out” button
• Put the number 1 in the field marked “ID of pet to return”
• Click the “Execute” button
• Scroll down to the Response body and verify that a record for a pet has been returned (if a record was not returned, try the request again with a different ID in the “ID of pet to return” field)
Step 2:
Step 3:
• Launch Postman
• In the top middle of the screen, verify that you see the word “GET” in the HTTP verb dropdown
• Click the “Send” button, and verify that you receive a response code of 200 OK, and that the response body contains the record for the pet
Комментарии