Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful web services

I am new to RESTful web services. We are taking the REST route for building our public web services to be consumed by out clients.And i had a few questions.

Are there any kind of limitation with pure REST webs services? and if yes then would a hybrid REST web service take care of those limitations?

I am thinking about using SSL + Hash Message Authentication Code (HMAC) in Authorization header for security along with IP based based filtering. what do you guys think about it?

Are there any good client side tools for testing? Currently i am using the following http://code.google.com/p/rest-client/

And what about some kind of client side code generation tool?

The following links are my source of info.

http://msdn.microsoft.com/en-us/library/dd203052.aspx

http://blogs.msdn.com/b/endpoint/archive/2010/01/07/getting-started-with-wcf-webhttp-services-in-net-4.aspx

like image 791
ps. Avatar asked Jul 21 '10 18:07

ps.


People also ask

What is meant by RESTful web services?

RESTful Web Services are basically REST Architecture based Web Services. In REST Architecture everything is a resource. RESTful web services are light weight, highly scalable and maintainable and are very commonly used to create APIs for web-based applications.

What are examples of RESTful web services?

Facebook, Twitter, and Google expose their functionality in the form of Restful web services. This allows any client application to call these web services via REST.

What is REST API and RESTful web services?

REST stands for representational state transfer. It is a set of constraints that set out how an API (application programming interface) should work. If an API is RESTful, that simply means that the API adheres to the REST architecture.

What are RESTful webseries?

Web services based on REST Architecture are known as RESTful web services. These webservices uses HTTP methods to implement the concept of REST architecture. A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.


2 Answers

The first thing to keep in mind is that a REST service should be stateless, which is very different when compared to a SOAP/RPC type of service interface. Using REST methodology requires you to rethink how you want your clients to interact with the service, breaking down the interactions into clear and concise method calls.

REST
+ Lightweight messages, very little overhead (other than the XML itself)
+ Easily readable results, can easily test with a web browser
+ Easy to implement
- Looser interface, loose type checking

SOAP
+ More rigid, with a strict contract definition
+ Plenty of development tools available.

Looking through the WCF MSDN documentation, WCF SOAP support was integrated from the start while REST support is a recently added feature. I myself am having a hard time finding documentation for authentication/security for REST services, as most of the documentation is directed towards SOAP.

Client side generation tools: I haven't come across any for REST services as REST doesn't define a service contract as SOAP does. WADL is an attempt to do that for REST services. http://en.wikipedia.org/wiki/Web_Application_Description_Language http://wadl.codeplex.com/

I'm interesting in reading more responses dealing with authentication and security, as I'm looking into that myself.

like image 193
MonkeyWrench Avatar answered Sep 28 '22 13:09

MonkeyWrench


This is a good starting point of a WCF REST WebService:

REST / SOAP endpoints for a WCF service

(BTW: Stackoverflow has nice REST kind of urls.) You can test a REST service with just a web browser (Go to the url and get the XML or JSON). Fiddler is also good tool, and FireBug-plugin for FireFox. I usually make a thin service-interface project and a separate (unit-tested) logics-project.

For authentication I would first generate a Guid and a timestamp. Then based on those a hash (.NET supports SHA256 and SHA512). The Guid can be stored to server (database table) to map it some concrete numerical id. Then you can have a rest url like:

/myobject/1?timestamp=20100802201000&hash=4DR7HGJPRE54Y 

and just disable the hash & timestamp check in development environment (e.g. with AOP). With timestamp I would check that the stamp is between 15 minutes back and forward in time (=should be enough to prevent attacks).

Will your service be visible to the public/internet and is your client a jQuery or Silverlight -client? Then you still have a problem: You don't want to include a secret key in the client software code.

So you need to generate hash in server and some kind of cookie to store the client session. (This can be done e.g. with a separate login-page/application in a folder with different config-file.) I remember that this book did have something on the topic:

If you want to enable the HttpContext when using WCF, you need to set <serviceHostingEnvironment aspNetCompatibilityEnabled="true"> under <system.serviceModel>. Then you can check current user identity from HttpContext.Current.User.Identity.Name.

However, if you want to make a pure REST service then you don't use cookies, but a HTTP Basic Authentication coupled with SSL/TLS for each call.

I think that it's easy to make a client with just LINQ2Xml or jQuery so maybe client generation is not needed.

Or you can also have both, a SOAP and a REST interface, and use a service reference to make a client.

like image 44
Tuomas Hietanen Avatar answered Sep 28 '22 13:09

Tuomas Hietanen