How to specify the Content-Type in your API REST

In the previous posts we talked a bit about how to create your REST Interfaces. Usually, when you are developing this kind of interfaces you use a JSON format in your payload. But, there is no default way to tell that to your API that the content-type that is replying is JSON. So, in this post I’m going to tell you how to do it.

First, we are going to talk with a first test to see the current problem. If I test our API we get this kind of response:

2015-11-01_15-56-43

You can see the payload is a correct JSON string, but if you try to check it using the JSON tab inside the SOAPUI you are going to face this error message: “The content you are trying to view cannot be viewed as JSON”. That’s because as you can see we have not a Content-Type HTTP header that identify this payload as a JSON string.

But, we can change that inside our process, using the same way we use to map the output value from the process. Using the “Bind” button inside the REST Dispatch and Reply activity.

2015-11-01_15-59-59

And the, after this change we can run a different test and check that now we have no problem trying to show the content as JSON String:

2015-11-01_16-04-58

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s