目前正在学习接口测试,现发布接口文档,接下来的测试依赖于这份接口文档
下图是整理的接口文档:
接口文档:
- 创建token:
请求方式:post
Url:https://restful-booker.herokuapp.com/auth
请求参数:
Header
字段 | 类型 | 描述 |
Content-Type | string | Sets the format of payload you are sending 默认值: application/json |
Request body
字段 | 类型 | 描述 |
username | String | Username for authentication 默认值: admin |
password | String | Password for authentication 默认值: password123 |
Success 200
字段 | 类型 | 描述 |
token | String | Token to use in future requests |
- 获取预定的ID
请求方式:GET
https://restful-booker.herokuapp.com/booking
参数
字段 | 类型 | 描述 |
firstname可选(可选) | String | Return bookings with a specific firstname |
lastname可选可选) | String | Return bookings with a specific lastname |
checkin可选可选) | date | Return bookings that have a checkin date greater than or equal to the set checkin date. Format must be CCYY-MM-DD |
checkout可选可选) | date | Return bookings that have a checkout date greater than or equal to the set checkout date. Format must be CCYY-MM-DD |
Success 200
字段 | 类型 | 描述 |
object | object[] | Array of objects that contain unique booking IDs |
bookingid | number | ID of a specific booking that matches search criteria |
- 获取预定信息
Returns a specific booking based upon the booking id provided
GET
https://restful-booker.herokuapp.com/booking/:id
curl -i https://restful-booker.herokuapp.com/booking/1
Header
字段 | 类型 | 描述 |
Accept | string | Sets what format the response body is returned in. Can be application/json or application/xml 默认值: application/json |
Url Parameter
字段 | 类型 | 描述 |
id | String | The id of the booking you would like to retrieve |
Success 200
字段 | 类型 | 描述 |
firstname | String | Firstname for the guest who made the booking |
lastname | String | Lastname for the guest who made the booking |
totalprice | Number | The total price for the booking |
depositpaid | Boolean | Whether the deposit has been paid or not |
bookingdates | Object | Sub-object that contains the checkin and checkout dates |
checkin | Date | Date the guest is checking in |
checkout | Date | Date the guest is checking out |
additionalneeds | String | Any other needs the guest has |
HTTP/1.1 200 OK
{
"firstname": "Sally",
"lastname": "Brown",
"totalprice": 111,
"depositpaid": true,
"bookingdates": {
"checkin": "2013-02-23",
"checkout": "2014-10-23"
},
"additionalneeds": "Breakfast"}
4.创建预定
Creates a new booking in the API
POST
https://restful-booker.herokuapp.com/booking
curl -X POST \
https://restful-booker.herokuapp.com/booking \
-H 'Content-Type: application/json' \
-d '{
"firstname" : "Jim",
"lastname" : "Brown",
"totalprice" : 111,
"depositpaid" : true,
"bookingdates" : {
"checkin" : "2018-01-01",
"checkout" : "2019-01-01"
},
"additionalneeds" : "Breakfast"}'
Header
字段 | 类型 | 描述 |
Content-Type | string | Sets the format of payload you are sending. Can be application/json or text/xml 默认值: application/json |
Accept | string | Sets what format the response body is returned in. Can be application/json or application/xml 默认值: application/json |
Request body
字段 | 类型 | 描述 |
firstname | String | Firstname for the guest who made the booking |
lastname | String | Lastname for the guest who made the booking |
totalprice | Number | The total price for the booking |
depositpaid | Boolean | Whether the deposit has been paid or not |
checkin | Date | Date the guest is checking in |
checkout | Date | Date the guest is checking out |
additionalneeds | String | Any other needs the guest has |
Success 200
字段 | 类型 | 描述 |
bookingid | Number | ID for newly created booking |
booking | Object | Object that contains |
firstname | String | Firstname for the guest who made the booking |
lastname | String | Lastname for the guest who made the booking |
totalprice | Number | The total price for the booking |
depositpaid | Boolean | Whether the deposit has been paid or not |
bookingdates | Object | Sub-object that contains the checkin and checkout dates |
checkin | Date | Date the guest is checking in |
checkout | Date | Date the guest is checking out |
additionalneeds | String | Any other needs the guest has |
HTTP/1.1 200 OK
{
"bookingid": 1,
"booking": {
"firstname": "Jim",
"lastname": "Brown",
"totalprice": 111,
"depositpaid": true,
"bookingdates": {
"checkin": "2018-01-01",
"checkout": "2019-01-01"
},
"additionalneeds": "Breakfast"
}}
5.更新预定消息
Updates a current booking
PUT
https://restful-booker.herokuapp.com/booking/:id
curl -X PUT \
https://restful-booker.herokuapp.com/booking/1 \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Cookie: token=abc123' \
-d '{
"firstname" : "James",
"lastname" : "Brown",
"totalprice" : 111,
"depositpaid" : true,
"bookingdates" : {
"checkin" : "2018-01-01",
"checkout" : "2019-01-01"
},
"additionalneeds" : "Breakfast"}'
Header
字段 | 类型 | 描述 |
Content-Type | string | Sets the format of payload you are sending. Can be application/json or text/xml 默认值: application/json |
Accept | string | Sets what format the response body is returned in. Can be application/json or application/xml 默认值: application/json |
Cookie可选 | string | Sets an authorisation token to access the PUT endpoint, can be used as an alternative to the Authorisation 默认值: token= |
Authorisation可选 | string | YWRtaW46cGFzc3dvcmQxMjM=] Basic authorisation header to access the PUT endpoint, can be used as an alternative to the Cookie header 默认值: Basic |
Url Parameter
字段 | 类型 | 描述 |
id | Number | ID for the booking you want to update |
Request body
字段 | 类型 | 描述 |
firstname | String | Firstname for the guest who made the booking |
lastname | String | Lastname for the guest who made the booking |
totalprice | Number | The total price for the booking |
depositpaid | Boolean | Whether the deposit has been paid or not |
checkin | Date | Date the guest is checking in |
checkout | Date | Date the guest is checking out |
additionalneeds | String | Any other needs the guest has |
Success 200
字段 | 类型 | 描述 |
firstname | String | Firstname for the guest who made the booking |
lastname | String | Lastname for the guest who made the booking |
totalprice | Number | The total price for the booking |
depositpaid | Boolean | Whether the deposit has been paid or not |
bookingdates | Object | Sub-object that contains the checkin and checkout dates |
checkin | Date | Date the guest is checking in |
checkout | Date | Date the guest is checking out |
additionalneeds | String | Any other needs the guest has |
HTTP/1.1 200 OK
{
"firstname" : "James",
"lastname" : "Brown",
"totalprice" : 111,
"depositpaid" : true,
"bookingdates" : {
"checkin" : "2018-01-01",
"checkout" : "2019-01-01"
},
"additionalneeds" : "Breakfast"}
6.部分更新预定消息
Updates a current booking with a partial payload
PATCH
https://restful-booker.herokuapp.com/booking/:id
curl -X PUT \
https://restful-booker.herokuapp.com/booking/1 \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Cookie: token=abc123' \
-d '{
"firstname" : "James",
"lastname" : "Brown"}'
Header
字段 | 类型 | 描述 |
Content-Type | string | Sets the format of payload you are sending. Can be application/json or text/xml 默认值: application/json |
Accept | string | Sets what format the response body is returned in. Can be application/json or application/xml 默认值: application/json |
Cookie可选 | string | Sets an authorisation token to access the PUT endpoint, can be used as an alternative to the Authorisation 默认值: token= |
Authorisation可选 | string | YWRtaW46cGFzc3dvcmQxMjM=] Basic authorisation header to access the PUT endpoint, can be used as an alternative to the Cookie header 默认值: Basic |
Url Parameter
字段 | 类型 | 描述 |
id | Number | ID for the booking you want to update |
Request body
字段 | 类型 | 描述 |
firstname可选 | String | Firstname for the guest who made the booking |
lastname可选 | String | Lastname for the guest who made the booking |
totalprice可选 | Number | The total price for the booking |
depositpaid可选 | Boolean | Whether the deposit has been paid or not |
checkin可选 | Date | Date the guest is checking in |
checkout可选 | Date | Date the guest is checking out |
additionalneeds可选 | String | Any other needs the guest has |
Success 200
字段 | 类型 | 描述 |
firstname | String | Firstname for the guest who made the booking |
lastname | String | Lastname for the guest who made the booking |
totalprice | Number | The total price for the booking |
depositpaid | Boolean | Whether the deposit has been paid or not |
bookingdates | Object | Sub-object that contains the checkin and checkout dates |
checkin | Date | Date the guest is checking in |
checkout | Date | Date the guest is checking out |
additionalneeds | String | Any other needs the guest has |
HTTP/1.1 200 OK
{
"firstname" : "James",
"lastname" : "Brown",
"totalprice" : 111,
"depositpaid" : true,
"bookingdates" : {
"checkin" : "2018-01-01",
"checkout" : "2019-01-01"
},
"additionalneeds" : "Breakfast"}
7.删除预定
Returns the ids of all the bookings that exist within the API. Can take optional query strings to search and return a subset of booking ids.
DELETE
https://restful-booker.herokuapp.com/booking/1
curl -X DELETE \
https://restful-booker.herokuapp.com/booking/1 \
-H 'Content-Type: application/json' \
-H 'Cookie: token=abc123'
Header
字段 | 类型 | 描述 |
Cookie可选 | string | Sets an authorisation token to access the DELETE endpoint, can be used as an alternative to the Authorisation 默认值: token= |
Authorisation可选 | string | YWRtaW46cGFzc3dvcmQxMjM=] Basic authorisation header to access the DELETE endpoint, can be used as an alternative to the Cookie header 默认值: Basic |
Url Parameter
字段 | 类型 | 描述 |
id | Number | ID for the booking you want to update |
Success 200
字段 | 类型 | 描述 |
OK | String | Default HTTP 201 response |
HTTP/1.1 201 Created
8.健康监测
Ping - HealthCheck
A simple health check endpoint to confirm whether the API is up and running.
GET
https://restful-booker.herokuapp.com/ping
curl -i https://restful-booker.herokuapp.com/ping
Success 200
字段 | 类型 | 描述 |
OK | String | Default HTTP 201 response |
HTTP/1.1 201 Created