0

I'm a newbie both in SOAP and REST programming.

  • In SOAP the structure and the fields of the entities being exchanged are always well and unambiguously documented in the WSDL.

  • I think the same does not happen in REST.

How is the developer of the REST API supposed to document the structure and all the fields of the JSON objects, representing the entities being exchanged?

GionJh
  • 2,742
  • 2
  • 29
  • 68

2 Answers2

1

REST and SOAP can't be compared directly, as they are very different things. You can implement REST over SOAP if you want, but not the opposite. I recommend reading this answer.

In RESTful APIs you are supposed to document your media-types properly and let the interaction be driven by the underlying protocol, but don't look for that in most of the HTTP APIs that call themselves REST. They are using the term as a buzzword and often do the opposite of that, documenting the protocol instead of the media-types.

For instance, if you have an User resource, you are supposed to have a proper media-type for it in a format like JSON or XML that looks like application/vnd.mycompany.user.v1+json, and your documentation should describe what this JSON document looks like so the client knows what to expect. This doesn't have to be as strict as a WSDL. In fact, it can be a human readable documentation like you would do for documenting a class API or something like that.

The client can say what media-types he is prepared to accept with the Accept header. For instance, if a client wants the v1 representation in JSON, he can use something like:

GET /users/xyz
Accept: application/vnd.mycompany.user.v1+json

If he wants the v2 representation in XML, he can use something like:

GET /users/xyz
Accept: application/vnd.mycompany.user.v2+xml

And if he simply wants JSON and will let the server decide what to do, he can use a generic media-type and figure out what the server threw at him by checking the Content-Type response header.

GET /users/xyz
Accept: application/json

However, keep in mind that most of the so called REST APIs you'll find don't use custom media-types like this. Instead, they use the same generic media-types like application/json and application/xml everywhere. That means the clients have to identify resources through URI semantics and relations, and that's not REST at all. I'm not saying it's wrong, it's simple and works for many problems, but it's not REST and it doesn't solve the same kind of problems REST really intends to solve.

Community
  • 1
  • 1
Pedro Werneck
  • 40,902
  • 7
  • 64
  • 85
  • So if I understand correctly JSON objects fields are often described in natural language or are not specified at all? – GionJh Apr 10 '15 at 06:26
  • They are specified in any way you want. What matters is the client developer knowing the media-type information beforehand. – Pedro Werneck Apr 10 '15 at 12:53
-1

REST does not establish or recommend a way for you to structure your data. It's only meant to make it easy for anyone to figure out which methods and entities your API supports. You don't even necessarily need to output JSON in your REST API.