Postman Testing the Web API

Source: Internet
Author: User

How do I view a query string?

→ Enter the URL that contains the query string, for example: http://localhost:54176/api/ProductCategories?name=darren&age=25
→ Click the params, the query string is stored as a set of key-value teams
→ Select key-value pairs, right-select "encodeURIComponent" to encrypt keys or values


How to use body?

→form-data option, enter form data
→x-www-form-urlencoded options, enter form data, postman automatic encryption
→raw option, enter JSON data

{
"Name": "",
"Username": ""
"Age": 25
}
→binary options, upload pictures, audio, video, etc.

Here are some APIs to test for:

Get/categories
Post/categories
Put/categories/{id}
Get/categories/{id}
Delete/categories/{id}

Post/categories/{id}/products
Get/categories/{id}/products
Delete/categories/{id}/products/{productid}
Get/categories/{id}/products/{productid}
Put/categories/{id}/products/{productid}


GET request test?

→ Click no environment create environment variable

Host:http://localhost
port:8080

→get Request

GET {{Host}}:{{port}}/categories
GET {{HOST}}:{{PORT}}/CATEGORIES/1
GET {{host}}:{{port}}/categories/1/products

POST request test?

Create Cateogory

= = Request

POST {{Host}}:{{port}}/categories

Headers:

Content-type:application/json

Body:

{
"Name": ""
}

= = Response

Status 201 Created

{
"id": "1",
"Name": "",
"Products": []
}

Create product


= = Request

POST {{host}}:{{port}}/categories/1/products

Headers:

Content-type:application/json

Body:

{
"Name": "",
"Features": ["H", "O"]
}

= = Response

Status 201 Created

{
"id": "1",
"Name": "",
"Features": ["H", "O"]
}


put request test?

= = Request

PUT {{HOST}}:{{PORT}}/CATEGORIES/1

Headers:

Content-type:application/json

Body:

{
"Name": ""
}

= = Response

Status OK

{
"Message": ""
}


delet request a test?


= = Request

DELETE {{HOST}}:{{PORT}}/CATEGORIES/1


= = Response

{
"Message": ""
}


Query parameters request string test?

= = Request

GET {{Host}}:{port}/categories/1/products?name=h

= = Response

Status OK

[
{
"id": "1",
"Name": "H",
"Features": ["H",...]
},
{
"id": "1",
"Name": "H",
"Features": ["H",...]
}
]

Verify authorization?

Verify who's problem is resolved. Authorization to solve the problem.

The usual scenario is:

→ Enter user name and password

POST .../auth/login


Headers:

Content-type:application/json

Body:

{
"Login": "",
"Password": ""
}

→ service side return token

Get token in response

→ request A token in the headers again

GET: /categories

Headers:

Token: .....
Content-type:application/json

Postman Testing the Web API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.