知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

    • 扩展

    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

    • Web

      • Theory:World Wide Web
      • Theory:HTTP
      • Theory:HTTP URL
      • Theory:HTTP messages
      • Theory:MVC
      • Theory:Introduction to Spring Web MVC
      • Theory:REST
      • Theory:Postman
        • Installation
        • GET requests
        • POST requests
        • Other requests
        • Conclusion
      • Theory:Getting data from REST
      • Theory:Posting and deleting data via REST
      • Theory:REST Exception handling
      • Theory:Handling requests with bodies
      • Theory:Domains
      • Theory:HTTP Basic Auth
      • Theory:IP
      • Theory:Authentication and Authorization
      • Theory:OAuth
      • Theory:Java 11 HTTP client
    • Spring boot

  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • Web
Jim
2022-07-22
目录

Theory:Postman

If you already know something about REST services but haven't quite used them yet, it's time to try! REST requests are simple HTTP requests, but it's not convenient to make them through a browser as you'd usually do with most of the web content. You need a client to create requests, and Postman (opens new window) is a good one to try out.

提示

We will use endpoints of the free API server Reqres (opens new window) to make our example requests. It has the implementation of all basic HTTP methods: GET, POST, PUT, DELETE.

# Installation

Postman is a collaboration platform for API development. It has more functions than a simple API client, but all we need now is its ability to create requests to API endpoints.

You can get the application on Postman's official website (opens new window). Once you download the executable file for Windows or an archive for Linux, unpack it if needed and run the app. You should see a page like this:

img

Using Postman is free, so you can use your email or Google account to sign in. This will help you share your workspace on several devices. The registration is not obligatory, so you can close this window for now and start using Postman anonymously.

提示

We use Postman 7.15.0 for our illustrations here. The UI interface of your version may look slightly different, but the behavior of the application should be the same.

# GET requests

We are almost ready to make the first request. For this example, we will use a free test API server. Reqres API has several endpoints; you can get their descriptions on the official site (opens new window).

Postman is similar to a browser: you have tabs for your requests. Let's open the first one. Just hit the plus tab, and Postman will show the full panel.

img

To create a simple GET request without query parameters, add the address of an endpoint of the service. In the image you can see that we use https://reqres.in/api/users/2 for this purpose. Then press the Send button*,* and you will see a nicely formatted response.

img

If you want to use any query parameters, you can add them as key-value pairs. Notice that we used endpoint https://reqres.in/api/users this time.

img

Query parameters and key-value pairs are interchangeable in the application, so you can use any method you want. Postman will fill the other one automatically.

We know how to get data from the server, but sometimes we need to send data with POST requests, so let's see how you can do it with Postman.

# POST requests

A useful feature of POST requests is that we can fill the body of it with sensitive data. If we send our login and password through query parameters, it's easy to read them for someone who sees the traffic from your computer, for example, your internet service provider. We will try our best with registration and authentication to the server through API requests, but do not use real data for it though.

To create a POST request, open a new tab as you did earlier. Reqres allows you to use only defined emails that you receive in the previous example at the endpoint https://reqres.in/api/register. Let's choose "tracey.ramos@reqres.in" as the user's login for the registration. Change the request type to POST, add key-value pairs with email and password (any password you want) in the body of the request, and press Send:

img

We receive a response with a token. Tokens are identifiers that you can use for authorization. We almost repeated our previous requests, but this time choosing different parameters.

Sometimes it's preferable to use JSON to send data to the server, for example, when we have nested fields. Though we don't need to make a nested structure to send a login request, we try to make a JSON to show out how it works.

Choose a raw format for a body and JSON type for the data type. Then paste JSON with email and password to the editor and send the request to the server:

img

And again we succeed and get a token.

# Other requests

Postman allows you to create HTTP requests with other methods: DELETE, PUT, PATCH... You should select the one you want as the request type:

img

You know enough to fill the fields by yourself and practice DELETE, PUT, PATCH with the Reqres API (opens new window) server.

提示

Before using any API, do not forget to read the documentation first, or you can make some inappropriate changes on the server.

Now you are ready to send a request to any server you want!

# Conclusion

Postman is a simple and useful tool for making API requests. It includes all basic requests like POST, GET, PUT, DELETE, etc. You can use it as an API testing tool to reliably check HTTP requests.

编辑 (opens new window)
#Tool Guide#REST#HTTP
上次更新: 2022/10/12, 17:01:25
Theory:REST
Theory:Getting data from REST

← Theory:REST Theory:Getting data from REST→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式