Mimetypes for RESTful API

The Sun Cloud API at http://kenai.com/projects/suncloudapis/pages/Home is a good example for a RESTful API. True for RESTful principles, when you access a resource, you get more or less than representing that resource.

The Content-Type header in the response tells you what the type of this resource is, for example application / vnd.com.sun.cloud.Snapshot + json. The sun recorded these mimetics using IANA.

How practical is this overall at the moment? Most of the APIs I've seen used the Content-Type "application / json". This suggests that the answer is JSON, but nothing more. You must have something in the JSON object as a type property in order to know what it is.

I am developing a RESTful API (which will not be published, so I will not register mimetypes). I used RESTEasy, and I believe that even if I specify the full mimetype type, the Content-Type in the response header will be exactly what the Accept request header says. If the request requests "application / * + json" by default, the response header will have "application / * + json". Perhaps I will fix this by changing the title before the answer goes blank, but should I try to do this? Or should the answer have a wildcard, like a request?

Or do I just need to maintain "application / json", as most APIs do?

Additional thoughts added later:

: HTTP HTTP ?

HTTP , ( ), "Content-Type" "" .

HTTP , "" 200 OK, " " - , "application/json" , , , , , . RESTful, RESTful. (HTTP - RESTful, ).

. HTTP , , ; , "401 Unauthorized" , .

+5
3

"application/json", API?

.

- RESTful , . - - API. - . , REST .

IANA.

. AFAIK, IANA. , application/vnd.com.example.app.foo + json, . , , . .

+2

vnd.mycompany.mymediatype + xml . . , .

, /xml application/json - , , REST. , (, Javascript) .

+4

- , mimetype? - mimetype, , mimetype application/json?

My 2 cents. If the API is not made public, I see no reason for the full mimetype type. The application mimetic / json should be more than enough. You already know the json type that returns the response. If the API eventually becomes publicly available, then worry about a full mimetic ... or just let people know.

0
source

All Articles