It is posted as a memorandum. I would appreciate it if you could comment if there are any deficiencies.
This article This is a memorandum when a super beginner finally confirmed the operation of Put request using [** Talented API Tester **](about ## Talented API Tester).
** Details of the program tested this time ** Languages used: Java8, Java Servlet
Type: Put request Data passed in the request: JSON format Data to be sent in response: JSON format
We have confirmed this operation.
It is an extension of Google Chrome. If you use this, you can check the operation of server-side programs under development.
Download here [https://chrome.google.com/webstore/detail/talend-api-tester-free-ed/aejoelaoggembcahagimdiliamlcdmfm )
Talented API Tester for beginners here (Other pages in Qiita)
The official outline is here
Even if I looked at the above site, it didn't make sense. (The person who writes is not bad. I have no knowledge) So from here on, like me, is it a beginner and http communication? ?? server? ?? I will write it for people in that state. (To me who is forgetful)
Http communication and the mechanism of Servlet are prerequisite knowledge. Please check each one.
―― 1. Create a request you want to send to your server (your app, program) --Create a new request --Method selection --Address input --HEADER and BODY input
―― 2. Start your own server ―― 3. Send a request ―― 4. Check the response → End the test if the response is intended
Make a request with this Tester that you want to send to your server (your app, program).
To make a request, you need to make a Project. So click "+ Project" Create a new project.
At this time, it is okay to decide the name of the project appropriately. I created a project called "aaa". It looks like this when created.
Then, "add request" will appear in the center of the screen, so click on it to create a new request. (The name is appropriate and OK)
I'm naming it "Request1" that was entered from the beginning.
In the initial state, it is "GET", so select the method you want to test. I want to test PUT requests, so I use "PUT".
Like this
Well, this is the most difficult. I do not understand the meaning. But this time, I will not explain the address (URL?) In detail.
(** Addendum **: A kind person explained the address used this time in the comment. → Here)
It's just a test, so consider using the local loopback address to access the local server.
The address you actually enter looks like this http://127.0.0.1:8080 [path in the server? ]
I am [path in the server? Because] is specified as "/ api / notes" http://127.0.0.1:8080/api/notes
It will be.
This "api / notes" is the directory specified by the following code of Java Servlet. (It is described in the file of the program you want to test)
@WebServlet(
name = "CreateNewNote",
urlPatterns = {"/api/notes"}
)
So [path in the server? Enter the appropriate url Patterns according to the source code (method) you want to test.
When you enter
This time we will send JSON format data, so click "JSON" at the bottom of the BODY frame Then HEADER will automatically change to "Content-Type: application / json". I'm happy.
Click to see
Check out the common JSON format description.
Here, I will write notes when actually inputting to BODY.
** Indents, spaces and line breaks are NG ** ** Indents, spaces and line breaks are NG **
So, for example, when sending "title" and "body"
{"title": "Title", "body": "Content"}
Please enter. If you put a space strangely, it will not be recognized correctly (crying)
If you pay attention to this and enter BODY, it will be like this.
Your request is now complete! !! !! !! I'm happy.
Start the local server when you make a request.
This depends on each execution environment, but in the case of eclipse, click "Run" → select server Will start the local server.
Send the request created in 1. Click the blue "Send" button on the right side of the screen
Click the "Send" button and the response will be displayed below the request as shown in the image below.
If it works
This time, I'm writing code to create a class using the data passed in the request and send it back in JSON. It seems that it is working safely according to the specifications.
By the way, if it doesn't work, it looks like this
The number written in this colored part is a number called "Http status code", and the number is decided for each type of error. So please check it out.
Above
A memorandum when a super beginner finally confirmed the operation of Put request using [** Talented API Tester **](about ## Talented API Tester)
Is the end.
I would like to publish the source code of the Put request that sent this request in another article.
Recommended Posts