Logo
Section 1 / 8

Postman API 概览

学习 Postman API 的基础知识。

导入

Postman API 概览

学习 Postman API 的基础知识。

什么是 Postman?

Postman 是一个功能强大的 API 测试工具,具备丰富的特性,使我们能够以多种方式测试 API 端点。例如,我们可以使用 Postman 来测试在数据库中创建用户的端点。它还内置了多种请求类型,如 GET、POST、PUT 和 DELETE,可用于测试我们的端点。此外,Postman 让手动测试 API 变得简单,并提供了出色的自动化测试功能。

在本课程中,Postman 环境已经准备好。请运行下面的代码组件查看实际效果。

No configuration found for ID: 34992993b97e9e088a10598a79f1ce42ccd06ada15136ee43f67cbf1864c8138

...
The Postman sign-in screen
...
The Postman collections screen

No configuration found for ID: c0ad021bd5697709a5c79b6fccab6868e03caca89a87db785eb6b3298091f859

1cd testing-api-endpoints && npm start
1{{EDUCATIVE_LIVE_VM_URL}}:3000
1[ 2 { "id": "1", "product": "shirt", "price": 19.99 }, 3 { "id": "2", "product": "pants", "price": 49.99 }, 4 { "id": "3", "product": "hat", "price": 29.99 } 5]
1{{EDUCATIVE_LIVE_VM_URL}}:3000
...
The Postman test cases
1pm.test("given valid request, returns 200 status", () => { 2 pm.response.to.have.status(200); 3}); 4 5pm.test("given valid request, returns expected items length", () => { 6 const RESPONSE_DATA = pm.response.json(); 7 pm.expect(RESPONSE_DATA.length).to.eql(3); 8});

Next.js 与示例应用

测试注册端点