There are several ways to pass data when retrieving data from a client.
How to specify a variable after the URL after?
You can get it with request.queryParams
How to set a variable in the request body.
You can get it with request.queryParams.
If the same variable name is specified in the request parameter, the value will be overwritten and cannot be obtained.
Spark allows you to get part of the URL as a variable.
You can get it with request.params.
This is a sample of acquisition. How to receive the value when hitting this URL is
curl -X POST -d "postparam=hellopost" http://localhost:4567/hellopath/?urlparam=hellourl
```
The acquisition method is as follows.
#### **`python`**
````java
public static void main(String[] args) {
post("/:pathparam/", (request, response) -> {
System.out.println(request.param("pathparam")); // =>hello path is displayed
System.out.println(request.queryParams("urlparam")); // =>hellourl is displayed
System.out.println(request.queryParams("postparam")); // =>hellopost is displayed
return null;
});
}
Recommended Posts