Skip to content
Marlon Carvalho edited this page Jul 23, 2015 · 2 revisions

Medya Types define how a resource is represented. For example, if a POST request is made to your API with the Content-Type header defined as application/json, then the incoming request body should contain a String representing a JSON object. In the other hand, your API can respond to a request sending a response body containing a XML string and setting the Content-Type header to application/xml.

@API(path: 'beers')
@MediaType(consumes: const [MediaType.JSON], produces: const [MediaType.JSON])
class BeerAPI { }

You define which media type your API consumes and produces using the @MediaType annotation. Considering the example above, the consume attribute tells Darter to accept only requests with Content-Type equals to application/json. If a different value is provided in this header, then Darter will respond with a 415 (Unsupported Media Type). The produce attribute tells Darter to set the Content-Type header to application/json in the response.

The @MediaType annotations is a class-level and method-level annotation.

Clone this wiki locally