DHC - REST/HTTP API Client


213010_U6Xn_1185936.jpg

-------------------------------------------------------------------------------------------------------------------------------

Build requests

As a REST client, DHC by Restlet allows you to build a request and display its response.

Build a request

DHC provides a dedicated area to configure your request.

Request structure

This area maps the different request elements. The latter is summarized in the following diagram as a reminder.

Request diagram

Method

The method corresponds to the HTTP verb used. It identifies the action to execute on the resource.

Protocol

The protocol used to interact with a server e.g. HTTP or HTTPS.

Host, Port & Path

Host and port identify the target to contact to send the request. Once connected to the server, the path is used to select the resource to handle the request.

Query parameters

Query parameters are used to build the query string of the request. They contain data that does not fit conveniently into a hierarchical path structure.

Headers

HTTP Headers define the operating parameters of an HTTP transaction. They correspond to a list of key-value pairs.

Payload

Request payload corresponds to the data sent when supported. This applies to methods POST, PUT and PATCH.

DHC by Restlet defines four distinct sub areas:

  • the request URL and method;

  • the query parameters;

  • the headers and

  • the request payload.

GET method

The following screenshot describes the case of a GET method where no payload is used. You can distinguish the different parameters displayed.

The protocol

Request protocol

The host, port and path

Request host, port and path

The method (GET)

Request method

The query parameters

By default, the query parameter area is hidden and can be displayed by clicking the “?” character right after the address field. You can either directly leverage the URL to add them or use the form. The main difference is, when using the form, parameter values are automatically URL encoded.

Request query parameters

The headers

Request headers

POST method

A POST method follows the same approach but in addition a request payload can be added. Several modes are supported for payload content. The switch is done using the combobox on the top right hand corner of the body area.

Text content (text value)

For formats like raw text, JSON, XML or YAML, with syntax highlighting. In this case a text area can be used. DHC by Restlet provides a set of types right below the text area to directly set the corresponding content type value.

This screenshot shows you a JSON payload for which the application/json Content-Typeheader is automatically created:

POST method with text content

Content from file (file value)

In this case, DHC by Restlet provides an area to drag’n drop the file or select it explicitly. The tool automatically gets the associated mime type. When clicking on it, the Content-Type header is automatically created.

This screenshot shows you a File payload for which the image/png Content-Type header is automatically created:

Forms (form value)

DHC by Restlet supports both simple forms and multipart ones.

Simple forms

Only text form elements can be defined and the content type is set to application/x-www-form-urlencoded.

This screenshot shows you a simple form payload for which the application/x-www-form-urlencoded Content-Type header is automatically created:

POST method with simple form content

Multipart forms

You can mix file elements with text ones. In this case, the content type ismultipart/form-data.

This screenshot shows you a multipart form payload for which the multipart/form-dataContent-Type header is automatically created:

POST method with multipart form content

Disable query parameters or headers

DHC by Restlet also allows you to disable some elements in lists (query parameters and headers) without having to remove them. This is particularly useful when building your request to tweak it and reach the expected behavior.

This screenshot shows you a request for which the header is disabled (checkbox deselected):

Switch mode

You can also switch mode to edit and display things. This is very useful e.g. when you have access to the raw content or when managing it using a form view.


更多:chrome-extension://aejoelaoggembcahagimdiliamlcdmfm/dhc.html#help

转载于:https://my.oschina.net/u/1185936/blog/601576

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值