PUT
The HTTP PUT request method creates a new resource or replaces a representation of the target resource with the request payload.
We already know how to make basic API from the API Example Page.
This Page explains How to make PUT Method API, update data in the database, and Get a response from this PUT API!
Add New PUT Path (in APIs Page)
β‘οΈ Add New PUT Path (in Server Page).
As you know, we already made API and Server.
So, we just add the NEW PATH and Add this in the Server in Autoflow
Follow the below steps!
We will make below PUT /user/{user_id}
Then we will update data in the database by PUT /user/{user_id} with Request Body.
Before Starting, Assuming that the Clients is already connected, this page will only explain the post method.
1. Add New Path with URL Pathβ
We already made Autoflow API and Autoflow Server.
So we will use this which we made.
Then just add a new Path.
1.1 Click the Add Path button and write your Path name!β
First, we click the Add Path button. Then we will write the path name.
We select the PUT Method.
You can write the URL path Name whatever you want to write.
1.2 API page Overviewβ
When you added a New path, We can see below the new Path.
PUT/user/{user_id}
Also, you can make this path by OpenAPI schema on the right side!
2. Add a New Path to the Server!β
Let's Add a New Path to the Server!
As you know, we already made a Server from the API Example Page.
2.1. Click Server Page, Then Click Server Operation!β
Click Server Page, then Click Server Operation which we made it before!
2.2. Click Add API Operation, Then Click your new Path!β
Click Add API Operation, then Click your new PATH.
Now we can see the below screen.
The API has already been made and completed.
However, our goal is to send PUT /user/{user_id}
with URL PATH and Request Body
Now we can use PUT /user/{user_id}
3. Delete User Data using Action.β
Using PUT /user/{user_id}
Let's delete the user data in the database!
To parse Data, we should add Autoflow Action.
3.1 Click the Add Action buttonβ
To add an action, we should click the Add Action button.
3.2 Select Action.β
We have lots of Actions in Autoflow.
On this page, we will use Database Query Action.
Select Database
Then Select Query
3.3 How to use Database Query Action.β
This page's goal is to insert a query in the database from the PUT with URL PATH AND Request Body.
I will send PUT with Request URL PATH & Body
3.3.1 Select your Clientβ
Select your Client which you connected.
I will connect 'MySQL' database.
If you don't know how to connect Client, Click hereπ
3.3.2 Write UPDATE SQL in 'Query'β
Our goal is Insert Query in Database from PUT URL PATH.
Write UPDATE QUERY and Select 'Write' in Type.
I only wrote UPDATE `account` SET name = WHERE id = ;
Because I will put the values from PUT URL PATH & Request Body.
3.3.3 Add a Variable Name.β
Write the variable name in the Key field.
3.3.4 Drag the Param to where you want to Update.β
Let's drag the 'updated_id' and 'user_id' params to where you want to update!
3.3.5 Click String type in Paramsβ
We want to use the PUT URL Path.
So we will use this variable as one of the PUT URL Path.
3.3.6 Change to Data Typeβ
Click Data Type.
3.3.7 Write Path Scope!β
We can get PUT Request Body by request > body > new_name
.
So write the path below.
In the same way, user_id
proceeds the same way.
We can get PUT URL Path by request > path > user_id
.
So write path by below.
3.3.8 We are ready to PUT Request! πβ
3.3.9 Send a Database query as a Response.β
I want to PUT a Response in the database table.
So, I will add one more action to the response.
SELECT * FROM `account`;
then the QUERY result will be PUT Response.
4. Test PUT Request and Responseβ
I will use POSTMAN to PUT request with the URL Path & Request Body.
Before starting my user database is as below.
4.1 PUT Request with URL Path & Request Body.β
First, I will PUT with URL Path AND Request Body.
PUTURL: http://localhost:8080/user/2
Then I get the below response. Now we can see the URL Path user's data was updated in the MySQL database.
Second, I will check the result using Action.
Then I got the below response. Now we can see the URL Path user's data was updated in the MySQL database.