TheRest is a collection of libraries that allow you to build simple, flexible REST services quickly and easily. If you've already used WebSync, then you will be familiar with the aspect-oriented approach used by TheRest's server events.
TheRest provides a server implementation, which handles processing of the incoming requests, as well as client libraries for a wide variety of platforms to simplify the consuming of REST services and abstract away a lot of the underlying asynchronous communication.
TheRest uses an aspect-oriented approach similar to WebSync and WCF which allows you to define REST methods anywhere in your .NET web application:
[TheRestEvent(EventType.Post, "/user/")]
public static User CreateUser(object sender, TheRestEventArgs e)
{
return User.Insert(Json.Deserialize<User>(e.RequestJson));
}
[TheRestEvent(EventType.Get, "/user/{id}")]
public static User ReadUser(object sender, TheRestEventArgs e)
{
// Invalid ID? NotFoundException is
// automatically mapped to a 404 response.
return User.Select(e.GetParameter<Guid>("id"));
}
TheRest automatically translates exceptions to HTTP status codes. It provides a set of exception classes that are pre-mapped to their HTTP counterparts (such as the NotFoundException, which results in a 404), but any exception class can be mapped to a specific HTTP status code.
// map MyValidationException to a 400 Bad Request
TheRestServer.RegisterException<MyValidationException>(HttpStatusCode.BadRequest);
On the client-side, you can consume the REST services exposed by TheRest from any platform that supports basic HTTP requests. For convenience, we have included client libraries for the most popular platforms that abstracts away most of the work associated with setting up web requests, error handling, and serialization. The JavaScript library even takes care of all cross-domain considerations, making it possible to send requests to your REST services from any domain.
var client = new fm.therest.client('http://myserver/therest.ashx');
client.send({
path: '/user/123',
method: fm.httpMethod.Get,
onSuccess: function(e) {
// e.getData() has the user
},
onFailure: function(e) {
// e.getException() has the error details
// e.getResponseStatusCode() has the HTTP status code
}
});
TheRest is completely free to try. Check out our downloads page to get started (requires free registration).
We'll be glad to answer any questions you might have, just drop us a line!