900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > http接口测试工具——RESTClient

http接口测试工具——RESTClient

时间:2022-08-26 09:51:30

相关推荐

http接口测试工具——RESTClient

RESTClientis a Java Swing application for testing RESTful web services. It might be used for testing other HTTP communications too. This is a short introduction of this tool explaining its various features.

The First Step

RESTClient can be downloaded from/p/rest-client/downloads/list. It is a single Jar file. To run it, you need to have Java 5 installed. After downloading, Windows users need to double-click to start the application. Non-Windows users, fire up your command prompt/shell, and issue:

$ java -jar restclient-2.1-jar-with-dependencies.jar

The UI

Once it is started, you will see this UI:

As seen in the screenshot, the UI is divided into two sections. The top portion has the HTTP request details and the bottom portion has the HTTP response details. To get started, just enter the value “/” in the URL field. Now press the green “>>” button near to the URL field. You should find the response details in the Response section of the UI.

RESTful Web services Example

Now we will use RESTClient to learn how it can be used to test a RESTful web services. We will take the example of social bookmarking for example. If you do not have an account with this site, please sign up for a free account. The REST API of this service is documented in this page:/help/doc/api.html. For using this service, you have to request API key here:/help/doc/gettingaccess.html.

Once you get the API key, you are ready to start! Fire up RESTClient. We will do the following operations on :

List all the posts you made

Create a post (bookmark entry)

Change post

Delete post

Before we start trying out the features of , you have to understand the authentication mechanism of this site. In the authentication tab, make sure you give:

BASIC authentication method should be selected.

Preemptive can be selected (not mandatory). Having this selected will send the authentication details to the server even before the server challenges for it.

Give your BibSonomy username and API key as the password.

Now we jump on to the operations. All the operations will require that this authentication detail to be configured.

Operation 1: List all the posts you made

To list all the posts you have made, enter this URL in the URL box:

/api/posts?user=subwiz&resourcetype=bookmark

(Note: Replace all mentions of `subwiz" with your userid. `subwiz" is the author"s userid.)

Make sure you have entered the authentication details as mentioned. Now with the method entered as GET, hit the green “>>” button.

As you see in the body tab of the Response section, it has returned an XML saying that this user does not have any posts yet. We will be usingOperation 1further down in the tutorial to see the status of our additions, updations and deletions.

Operation 2: Create a post

To create a post, you have to hit this URL:

/api/users/subwiz/posts

The HTTP method to be used is POST for create operation. Make sure you select this option in the Method tab.

After selecting the POST method, the Body tab controls get enabled. Body is supported only for POST and PUT methods. In the Body tab, add the bookmark post detail in the following format:

<?xmlversion="1.0"?><bibsonomy><postdescription="OpenSource"><username="subwiz"/><tagname="opensource"/><tagname="java"/><groupname="public"/><bookmarkurl="/"/></post></bibsonomy> Make sure you change the content-type toapplication/xmland charset toUTF-8(click the Edit button near to the content-type/charset text field to change). Finally, it should look like:

Now execute the request by pressing the “>>” button. The response screen should be something similar to:

and:

Response status 201 means success. Make note of the hash returned (which in our case is: 03fb1f5d1634e4bd72e6ccdc0cdafcc2) in the body of the response. This will be needed for the next operation. Now performOperation 1to see your new post getting displayed.

Operation 3: Change post

The URL for updating a existing post is:

/api/users/subwiz/posts/03fb1f5d1634e4bd72e6ccdc0cdafcc2

For updating a post with new/changed data, HTTP PUT method is used. Select PUT from the Methods tab, and enter in the body text:

<?xmlversion="1.0"?><bibsonomy><postdescription="OpenSource"><username="subwiz"/><tagname="opensource"/><tagname="java"/><tagname="REST"/><bookmarkurl="/"intrahash="03fb1f5d1634e4bd72e6ccdc0cdafcc2"interhash="03fb1f5d1634e4bd72e6ccdc0cdafcc2"/></post></bibsonomy> As you see, we have added a new tag REST and updated the title. Also remember to set the Content-type and charset toapplication/xmlandUTF-8respectively. Execute the request, and performOperation 1to validate.

Operation 4: Delete post

The final operation is the DELETE operation. The URL for this is:

/api/users/subwiz/posts/03fb1f5d1634e4bd72e6ccdc0cdafcc2

From the Methods tab, select DELETE. If the DELETE operation is successful, the Response status code will be 200 OK. PerformOperation 1to validate.

Testing Using RESTClient

Another interesting feature in RESTClient is the ability to attach test scripts written in Groovy with each request. More on this is covered in thetutorial at the site.

Persisting Request et all

RESTClient also supports persisting request, response and request-response combination. This helps in record and playback support. These options are available in theFilemenu.

What Else?

RESTClient has been developed with active input from theREST-Discusscommunity. If you have any request (both bugs and features), justfile a issue.

Topics:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。