Own media type

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Own media type

Ivan
Hello,

Could someone describe what are the right steps to enable the support for own media type in Restlet?

An example, my server resource should support MediaType "application/vnd.aaa.bbb+json". I didn't find any info how to support just media types..

- do I need to call MediaType.register("application/vnd.aaa.bbb+json", "blablabla")?
- do I need to call getMetadataService.addExtension("xyz", MediaType.valueOf("application/vnd.aaa.bbb+json"))? and what should be the extension value "xyz"? Up to me?
- what should be the value of @Get? "xyz"?
- do I need to define why own class for the representation? The format of my media type is JSON, but I cannot use JsonRepresentation because its media type is "application/json".
- any code examples for using own media types?

Thanks in advance.

Ivan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Own media type

Ivan
Does anyone have an idea how to support own media type for a server resource? I can't believe everyone is fine with just standard types like application/json or application/xml.. Quite often to build truly RESTful system you have to define own media types. Unfortunately from the documentation it wasn't clear how to do in Restlet.

Ivan

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2888844
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Own media type

jlouvel
Administrator
Hi Ivan,

- do I need to call getMetadataService.addExtension("xyz",
MediaType.valueOf("application/vnd.aaa.bbb+json"))? YES

and what should be the extension value "xyz"? Up to me? YES as long as there
is no conflict with default extensions

- what should be the value of @Get? "xyz"? YES

- do I need to define why own class for the representation? The format of my
media type is JSON, but I cannot use JsonRepresentation because its media
type is "application/json". NO, you can use generic representation classes
such as WriterRepresentation

- any code examples for using own media types? Not sure, but there isn't
much more. Feel free to contribute a section to the user guide/wiki once you
got it working.

Best regards,
Jerome
--
http://www.restlet.org
http://twitter.com/#!/jlouvel


-----Message d'origine-----
De : Ivan [mailto:[hidden email]]
Envoyé : mardi 29 novembre 2011 09:33
À : [hidden email]
Objet : RE: Own media type

Does anyone have an idea how to support own media type for a server
resource? I can't believe everyone is fine with just standard types like
application/json or application/xml.. Quite often to build truly RESTful
system you have to define own media types. Unfortunately from the
documentation it wasn't clear how to do in Restlet.

Ivan

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=28888
44

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2889018
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Own media type

Ivan
Hi,

Thanks Jerome for your answers.

I also got a comment that custom media type info can be added during server resource initialization by calling getVariants().add(new Variant("​application/vnd.aaa.​bbb+json")).

Regarding WriterRepresentation. Using this I will have to basically re-write all the JSON related stuff that already exists in JsonRepresentation because after all my media type's format is JSON. Is it anyhow possible to use existing JsonRepresentation but make it return application/vnd.aaa.bbb+json media type instead of application/json?

Ivan

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2889232
Loading...