tags:

views:

38

answers:

2

Let's say I have the URI for a RESTful or other contract-less API. Is it possible to determine its interface programatically? I'm using C#/ASP.net MVC, not sure if that's important.

I understand that there won't be a published contract, but I'm wondering if there's something I'm not thinking of (there usually is).

+2  A: 

No. Unfortunately, you're right. There are usually no contracts with RESTful APIs other than the published documentation of it.

Pablo Santa Cruz
+1  A: 

If the system is RESTful then the returned representation will provide you with links to the available endpoints. These links are easy to discover programatically. See this example.

The content-type HTTP header should tell you what type of information is being returned. Assuming your client application understands that media type then you should have all the information you need to know to use the service.

Unfortunately, it has become commonplace to return generic media types like application/xml and application/json that tells you nothing more about the content than how to parse it. If that is the case then your client will need to store some additional information about what datatype is expected to come from a particular URL. This is nasty coupling but is a necessary evil until people start really to understand the "self-descriptive" REST constraint.

Darrel Miller