3

A third party company has written a set of ReST service. I've got all the code working, but in hindsight, to remove some of the leg work, I thought someone might know of a code generator that connects to the ReST service and works out what request and response objects need to be created and generate the code for those. I had a look on google, but didn't see anything suitable (maybe it's called something else).

I'm looking for functionality similar to adding a Web Reference in Visual studio, where it generates the proxy and the objects it requires for you.

The ReST service is written in Java, so I can't use any of the nice WCF stuff.

Mr Shoubs
  • 14,629
  • 17
  • 68
  • 107

3 Answers3

3

There is no standard way to describe RESTful services, so there is no tool to generate such proxies for you. There is no wsdl for REST (which is what Visual Studio uses for web references).

You can use REST libraries such as RESTSharp to make calls to service easier, using standard HTTP verbs and response codes, but you need to understand the API yourself.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
3

This isn't really possible i'm afraid, unless the publisher of the service specifically publishes meta data in some form about their service; and then it'll be a proprietary extension that you'll have to code specifically against yourself.

There's nothing built in to REST to enable self-description so there is no way of knowing what what collections etc are available, or what objects it needs/exposes until you actually invoke it.

An exception to this is something like an oData service where meta data about objects is published along with the object collections themselves - but then oData is a protocol built in a RESTful manner; that's different to it just being 'a REST service'.

As a result, you're at the mercy of the service authors to be dilligent and provide you with the information you need that can read by a machine and turned into code.

For example, if the data is transported with XML then they should also (imho) publish one or more XML schemas that describe the objects they will send to you and that they expect you to send to them.

That's the biggest battle - as writing code to actually interface with a REST service is probably the easiest; certainly much nicer than trying to code your own SOAP client!

Andras Zoltan
  • 41,961
  • 13
  • 104
  • 160
  • Thanks - they have provided me with an XSD file, which I think I can use the answer here (http://stackoverflow.com/questions/312551/generate-net-objects-from-known-xsd) to generate objects. – Mr Shoubs May 23 '11 at 14:19
0

You should check out F# type providers. They are able to sniff types and members from a "typical" API response, so you have InteliSense and typo checking for these. It's not a rigorous way to assert every possible property of output though and it won't help you with requests.

Lukáš Lánský
  • 4,641
  • 3
  • 32
  • 48