Request with body in REST API testing

38 views
Skip to first unread message

aostad

unread,
Dec 25, 2019, 1:06:25 AM12/25/19
to Serenity BDD Users Group
Hi,
I'm wondering how to prepare the body of a request and pass it as a string to "callEndpointHttpMethodPost(String url, String body)?

I mean the body usually includes multiple fields in JSON format. I'm not sure how to convert field names and their data and pass it as a string. Is there a sample/example for preparing a POST request with multiple body fields?
Let say the body of a POST request is:
{
  "firstName" : "Bob",
  "lastName" : "Smith",
  "age" : " 40",
  "occupation: "Software Engineer"
}
 

Should I pass the whole thing as a string like "{.......}"?

Thanks
Ali

Giang Nguyen

unread,
Dec 25, 2019, 8:33:13 AM12/25/19
to aostad, Serenity BDD Users Group
Hi,
I think you should use serialization POJO to Json via jackson/gson lib. See user guide of rest-assured to get more details.

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/thucydides-users/4ce849ca-f9bf-4e43-9833-29a696f3ef62%40googlegroups.com.

aostad

unread,
Dec 27, 2019, 1:00:41 AM12/27/19
to Serenity BDD Users Group
I'm using the sample serenity-cucumber-api-test code. based on this sample program, you should pass the body from *.feature file as a string. but there is no example to show how you pass the body to the mapping java code.


On Wednesday, 25 December 2019 05:33:13 UTC-8, Giang Nguyen wrote:
Hi,
I think you should use serialization POJO to Json via jackson/gson lib. See user guide of rest-assured to get more details.
On Wed, Dec 25, 2019 at 13:06 aostad <aostad...@gmail.com> wrote:
Hi,
I'm wondering how to prepare the body of a request and pass it as a string to "callEndpointHttpMethodPost(String url, String body)?

I mean the body usually includes multiple fields in JSON format. I'm not sure how to convert field names and their data and pass it as a string. Is there a sample/example for preparing a POST request with multiple body fields?
Let say the body of a POST request is:
{
  "firstName" : "Bob",
  "lastName" : "Smith",
  "age" : " 40",
  "occupation: "Software Engineer"
}
 

Should I pass the whole thing as a string like "{.......}"?

Thanks
Ali

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydid...@googlegroups.com.

Giang Nguyen

unread,
Dec 27, 2019, 4:51:24 AM12/27/19
to aostad, Serenity BDD Users Group
I haven’t used this but I found an example here. It may help you. See the complex scenario.

To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/thucydides-users/b12abf1c-3996-4617-a5c3-4207a53d1a45%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages