Answer
Types of API Parameters
1. Path Parameter
Used to identify a specific resource in the URL path. Specified in the URL and preceded by a colon :.
Example:
CODE
GET /users/:id → GET /users/123
Rest Assured Code:
Java
int userId = 123;
given()
.pathParam("id", userId)
.when()
.get("/users/{id}")
.then()
.statusCode(200);
✦
2. Query Parameter
Used to filter or sort data. Specified in the URL query string, separated by &.
Example:
CODE
GET /users?gender=female
GET /products?category=electronics&price=500
Rest Assured Code:
Java
given()
.queryParam("gender", "female")
.when()
.get("https://api.example.com/users")
.then()
.statusCode(200);
✦
3. Form Parameter
Used to send form data in the request body (like HTML form submissions). Content-Type is typically application/x-www-form-urlencoded.
Example:
CODE
POST /login
Content-Type: application/x-www-form-urlencoded
username=john&password=secret
Rest Assured Code:
Java
given()
.contentType("application/x-www-form-urlencoded")
.formParam("username", "john")
.formParam("password", "secret")
.when()
.post("/login")
.then()
.statusCode(200);
Quick Comparison
| Type | Location | Use Case |
|---|---|---|
| Path Param | URL path /users/{id} | Identify specific resource |
| Query Param | URL query ?key=value | Filter, sort, paginate |
| Form Param | Request body (form-encoded) | Submit form data |
