Parameter
Parameters are one of the essential components of the HTTP protocol, which is an optional entity but can be used in combination for various purposes.
We already know how to make basic API from the API Example Page.
This Page explains How to use API Parameter with GET Example!
Add New GET Path (in APIs Page)
β‘οΈ Add New GET 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 the below GET method with the URL Parameter.
We will send below URL with parameter
Then Getting a query result from Database user who is engineer and living in seoul.
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 new a Path with URL 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 with bracket {user_info}
.
In /user/{user_info}
, {user_info}
means that you can receive data from URL Parameters
And we select the GET 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.
GET/user/{user_info}
Also, you can make this path by OpenAPI schema on the rightside!
2. Add a New Path in the Server!β
Let's Add a new path in 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 the Server Page, then Click the Server Operation which we made it before!
2.2. Click Add API Operation, Then Click your new Path!β
Click the 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 a response using the URL path value.
Now we can use GET /user/{user_info}
3. Get Response using Action and URL path by API.β
We can already receive the URL path through the API.
Let's process this in Autoflow and getting a query result from database as a response.
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 getting a query in the database from the GET with parameters.
I will send GET with Request parameters.
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 SELECT SQL in 'Query'β
Our goal is SELECT Query in Database from PUT URL Parameters.
Write SELECT QUERY and Select 'read' in Type.
I only wrote SELECT `name` FROM `account` WHERE job = AND city =;
Because I will put the values from GET URL Parameters.
3.3.3 Add a Variable Name.β
Write the variable name in the Key field.
3.3.4 Drag the Params to where you want to SELECT.β
Let's drag the 'job' and 'city' params to where you want to SELECT!
3.3.5 Click String type in Paramsβ
We want to use the GET URL Parameter.
So we will use this variable as one of the GET URL Parameter.
3.3.6 Change to Data Typeβ
Click Data Type.
3.3.7 Write Path Scope!β
We can get GET Request query parameter by request > query > city
.
So write the path below.
In the same way, job
proceeds the same way.
We can get GET URL Path by request > query > job
.
So write path by below.
3.3.8 We are ready to GET Request! πβ
4. Test GET Request and Responseβ
I will use POSTMAN to GET request with the URL parameter & Request Body.
Before starting my user database is as below.
id | name | city | job |
---|---|---|---|
1 | eric | seoul | engineer |
2 | bobby | seoul | engineer |
3 | los | seoul | designer |
4 | bob | newyork | account |
5 | eric | montreal | lawer |
4.1 GET Request with URL Parameter.β
First, I will GET with URL Parameter.
GETURL: http://localhost:8080/user/hello?job=engineer&city=seoul
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.
Also, If you click Simulation, you can see your data like below.
You don't know how to use Simulation
in Autoflow?
Then, Click here! π