Web Service REST - With different types of record lists

Web Service REST - With different types of record lists

  

I'm tryng to create a REST web service that can expose multiple types of data, from various entities. I created a module that simulate my problem. (I simplified in on only module, but in reality is not)

My question is, based on the module above:

How can I set an output, if there are 3 types of data ( Computer Record List, Mouse Record List, Screen Record List).
The idea is to expose a web service and the Content-Type it has to be application/json or application/xml.

I can't convert previously the records to xml because if I set the output as text, the content-type will going to be as text/plain, and not application/json or application/xml.

Hi Pedro,

I'm not sure what your question is. Is it about the Computer/Mouse/Screen list, or about the content type, or both?

Hi Kilian

In the module I marked where is my problem. I want to build a  web service that can dinamically expose different types of record lists.

Kilian Hekhuis wrote:

Hi Pedro,

I'm not sure what your question is. Is it about the Computer/Mouse/Screen list, or about the content type, or both?



Hi Pedro,


You can have a Text output and just change the Content-Type header using the AddHeader action from the HttpRequestHandler extension to what you want, but you will have to do the serialization yourself.

Why do you need it to be a single method for all them?


Regards,

João Rosado

Hi João,


I tried that option already but i couldn't change the Content-Type. But I will replicate what I did to show if I did something wrong.

I need it to be a single method because I want to expose more than 40 entities and I don't want to build a web service for each one.


Regards,

Pedro Ramalho


João Rosado wrote:

Hi Pedro,


You can have a Text output and just change the Content-Type header using the AddHeader action from the HttpRequestHandler extension to what you want, but you will have to do the serialization yourself.

Why do you need it to be a single method for all them?


Regards,

João Rosado



Solution

But from a consumer point of view doesn't  it make sense  to have a different method for each "collection"? It's not very REST friendly to ignore the resource best practices.

Also from a development point of view I don't see why it helps only have a method with logic inside for 40 different sources, versus 1 method for each.


As for the Content-Type, ensure that the case of the string is correct. It really needs to have the C and T with capitals. 

Are you doint it inside the method or on a OnResponse? Think there is an issue open related to it not working correctly inside the OnResponse.


Regards,

João Rosado

Solution

Well it does make sense to have a different method for each "collection" but from a point of view of an external team (for example a team of Business Intelligence), it's easier to them to have one only web service to get the data from different entities, I think.

And from a development point of view, if the number of entities rises it's not easier to only serialize the data and automatically we expose the data? The only thing to do is to give the name of the new entity that we expose and the other team can access through that only web service.


Previously I tried on a OnResponse and it didn't work. I tried inside the method and appears to had solved the issue. 

I'll try and run more tests and if this solve the issue I'll mark this post as solved!


Thanks João Rosado.


Best Regards,

Pedro Ramalho


João Rosado wrote:

But from a consumer point of view doesn't  it make sense  to have a different method for each "collection"? It's not very REST friendly to ignore the resource best practices.

Also from a development point of view I don't see why it helps only have a method with logic inside for 40 different sources, versus 1 method for each.


As for the Content-Type, ensure that the case of the string is correct. It really needs to have the C and T with capitals. 

Are you doint it inside the method or on a OnResponse? Think there is an issue open related to it not working correctly inside the OnResponse.


Regards,

João Rosado