6

Say ,i have producer in java and consumer in dot net. Producer has a method that takes Employee as method parameter and creates employee in db.

For SOAP based ws, dot net client will hit WSDL and creates the stubs (including employee data representation in dot net). Now it can fill the object and send to producer.

I am not sure how it will work in restful webservices as there is no WSDL. How rest consumer will get to know what are the operations exposed by producer without any WSDL contract and how dot net consumer will get stubs (like employee data object) so that it can simply fill it and send across?

I know there is WADL(parallel to WSDL) in rest but looks like its not very prominent and not a standard as of now.

I am not getting how client side code will generate EmployeeData class so that it can fill it and send to producer? Will client manually create extra class (instead of proxy EmployeeData that used to be generated on the basis of WSDL using utilities available at client side)? Even if client has to do it manually, how client will know what is the class definition of EmployeeData class without wsdl or wadl?

M Sach
  • 33,416
  • 76
  • 221
  • 314
  • It's not the client that creates the stub code from WSDL. It's your dev environment. BTW, does it have to be REST? – JensG Mar 15 '14 at 18:14
  • I believe there are utilities for example in perl which can hit WSDL and generate the classes at run time which are required at client side for example :- EmployeeData object in this example – M Sach Mar 15 '14 at 18:18
  • Possible duplicate of [RESTful Services - WSDL Equivalent](https://stackoverflow.com/questions/4111646/restful-services-wsdl-equivalent) – Vadzim May 14 '19 at 07:38
  • hey I have same question. But I created rest web api in c# and it contains one class InputData. This object (JSON Serializable) must pass in body with post request to rest web api. But i want to consume this InputData Model class in another C# project. Like we add web reference url?wsdl, how can i create proxy InputData class in another c# project by adding my rest web api link? – Shrirang Mar 26 '20 at 10:48

2 Answers2

8

One important concept of REST is HATEOAS or Hypermedia as the Engine of Application State. What this means is that your client interacts with the REST service through hypermedia links that the service hands it.

Your REST web service has an entry point, say http://yourhost.com/rest. Your client will start by sending the request to that URL. Your service will respond with a resource that describes some or all the accessible resources and how to access them. You keep discovering and following links. This is how the API is published (and discovered).

Here's an awesome video describing this concept: Hypermedia APIs.

Through HATEOAS you can make your service API completely discoverable by just following hypermedia links.


There is no concept of top down/bottom up design in REST.

REST is about resources, not about method calls, which is basically what a WSDL describes.

Even if client has to do it manually, how client will know what is the class definition of EmployeeData class without wsdl or wadl?

It won't need to create an EmployeeData class. Say you needed to create a new Employee, you would send a GET request to /employees which would possibly return a response containing how to do that. That might be an XHTML response like so (among other things)

<form class="new-employee" action="/context/employees" method="PUT" >
    <input type="text" name="employee_name" />
    <input type="text" name="employee_age" />
    <input type="submit" name="submit" />
</form>

The response contains the exact format you need to follow to create a new employee. You need to submit the form to /context/employees with an HTTP PUT request containing those form parameters. This is HATEOAS. The hypermedia link is the /context/employees. The engine is following this link with a PUT request. The application state is that after this request, a new employee will exist.

Akira Yamamoto
  • 4,685
  • 4
  • 42
  • 43
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • This video seems to be specific to particular library i.e hypermedia APIs. Is n't it? Is there any specification by jax rs that how producer will expose its operations to consumer? Also Consumer will get the class that will be rquired at consumer side like EmployeeData in my example? – M Sach Mar 15 '14 at 18:25
  • @MSach No, the video is about the concept of an API described through hypermedia. Don't confuse a client/server library with API publishing. It's up to the developer/designer to publish their API. With REST, that should be done through HATEOAS. – Sotirios Delimanolis Mar 15 '14 at 18:28
  • If i take example of creating user at http://techmytalk.com/2013/06/22/restful-webservices-with-jersey/, here client is having User info object in advance. looks like here producer provided User Info object to consumer manually. Is it the only way ? If yes its too cumbersome . Is n't it? Can you tell me if i am new consumer of this create user service how should i proceed if there is no WSDL or WADL? – M Sach Mar 16 '14 at 03:49
  • @MSach Right. In that example, the developer of the service just re-used the same classes to test the service with the Jersey client. As I see it, you have two options as the API publisher: provide documentation describing the API in terms of HTTP or provide a client library (like facebook, twitter, etc.). – Sotirios Delimanolis Mar 16 '14 at 14:59
  • As you said "provide client library(like facebook,twitter )" . Does facebook/twitter etc provide client library for every possible client whether it is java,dot net,perl,pyton or any other language ? – M Sach Mar 19 '14 at 16:21
  • @MSach I don't know, you'd have to check. I'm assuming they at least have Java. – Sotirios Delimanolis Mar 19 '14 at 16:24
  • Instead of using GET to retrieve information on the data structure and parameter to pass wouldn't be better to use the method OPTIONS? – Dim13i Aug 08 '14 at 08:29
  • @Dim13i I didn't mean it in that sense. You can use any HTTP verb you like (and is supported by the API) to traverse the service. I meant _discoverable_ in the sense that true REST will make it obvious to you what your possible steps are. – Sotirios Delimanolis Aug 08 '14 at 15:13
1

Assuming that you're using the Json based WS - there is some tools that helps:

  1. there are json parsers that can turn json, or json schema files into POJO classes, and put some annotations used by Json parsing libraries - take a look here: http://www.jsonschema2pojo.org/
  2. I don't know any automated tool that can generate server stub in terms of all API calls etc. but there is a nice library to consume it - https://github.com/square/retrofit - you have to still put patches and methods signatures into interfase, but it's a way more convinient that playing with "pure" java.
  3. There are also some quite nice tools helping to generate and format documentation for WS - one I like most is swagger: https://helloreverb.com/developers/swagger

There is no (or at least I don't know about it) tool that allow to generate stub, data classes etc. as it can ve usually done with WSDL file.

piotrpo
  • 12,398
  • 7
  • 42
  • 58