Reputation: 95
I work with API Manager version 3.0.0.
In Publisher page in Resources,I need add two or more parameters when the type is BODY with the method HTTP is POST, similar to but only permits one when parameter is Body.
Is possible to add more than one parameter BODY? and how?
Edit:
Is possible have two parameters in BODY, whit this form in API Publisher-> API Definition -> Edit, edit the service that you need similar to:
/v1/nipCliente:
post:
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: "object"
properties:
id_usuario:
type: "string"
password:
type: "string"
nip:
type: "string"
required: false
responses:
200:
description: "ok"
security:
-
default: []
x-auth-type: "None"
x-throttling-tier: "Unlimited"
In the same page looks that:
In API Developer->Try Out, looks similar to:
Upvotes: 0
Views: 895
Reputation: 1100
Multiple body parameters in POST, PUT requests are NOT allowed by design because there can be only one payload for the request. [1]
If the request body contains multiple parameters, you can send it as a single json object.
The backend service method should be modified to accept the specific object model.
Ex: Say I want to send the following as the body.
{
"name" : "Joe",
"age" : 23,
"grade" : 9
}
The backend service method which expects Student object.
@POST
public Response studentPost(Student student) {
}
Student Object
public class Student{
String name;
int age;
int grade;
... getters/ setters ...
}
Or, you can use different parameters. i.e, query params + body + header params.
[1] https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object
Upvotes: 2