Skip to content

Commit

Permalink
Added v2.08 libs, updated README.md to include Backbone rest service …
Browse files Browse the repository at this point in the history
…instead
  • Loading branch information
mythz committed Mar 25, 2011
1 parent a517811 commit e45391d
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 45 deletions.
106 changes: 65 additions & 41 deletions README.md
Expand Up @@ -6,58 +6,82 @@ Service Stack is a high-performance .NET web services framework _(including a nu
that simplifies the development of XML, JSON, JSV and WCF SOAP [Web Services](https://github.com/ServiceStack/ServiceStack/wiki/Service-Stack-Web-Services).
For more info check out [servicestack.net](http://www.servicestack.net).

Simple web service example
==========================

[DataContract]
[RestService("/factorial/{ForNumber}")]
public class GetFactorial
{
[DataMember]
public long ForNumber { get; set; }
}

[DataContract]
public class GetFactorialResponse
{
[DataMember]
public long Result { get; set; }
}

public class GetFactorialService : IService<GetFactorial>
{
public object Execute(GetFactorial request)
{
return new GetFactorialResponse { Result = GetFactorial(request.ForNumber) };
}

static long GetFactorial(long n)
{
return n > 1 ? n * GetFactorial(n - 1) : 1;
}
}
Simple REST service example
===========================

//Register REST Paths
[RestService("/todos")]
[RestService("/todos/{Id}")]
public class Todo //REST Resource DTO
{
public long Id { get; set; }
public string Content { get; set; }
public int Order { get; set; }
public bool Done { get; set; }
}

//Todo REST Service implementation
public class TodoService : RestServiceBase<Todo>
{
public TodoRepository Repository { get; set; } //Injected by IOC

public override object OnGet(Todo request)
{
if (request.Id == default(long))
return Repository.GetAll();

return Repository.GetById(request.Id);
}

//Called for new and update
public override object OnPost(Todo todo)
{
return Repository.Store(todo);
}

public override object OnDelete(Todo request)
{
Repository.DeleteById(request.Id);
return null;
}
}

### Calling the factorial service from any C#/.NET Client
//no code-gen required, can re-use above DTO's
var serviceClient = new JsonServiceClient("http://localhost/myservice/");
var response = serviceClient.Get<GetFactorialResponse>("factorial/3");
Console.WriteLine("Result: {0}", response.Result);

var restClient = new JsonServiceClient("http://localhost/Backbone.Todo");
var all = restClient.Get<List<Todo>>("/todos"); // Count = 0

var todo = restClient.Post<Todo>("/todos", new Todo { Content = "New TODO", Order = 1 }); //todo.Id = 1
all = restClient.Get<List<Todo>>("/todos"); // Count = 1

todo.Content = "Updated TODO";
todo = restClient.Post<Todo>("/todos", todo); // todo.Content = Updated TODO

restClient.Delete<Todo>("/todos/" + todo.Id);
all = restClient.Get<List<Todo>>("/todos"); // Count = 0


### Calling the factorial service from jQuery

$.getJSON("http://localhost/myservice/factorial/3", function(e) {
alert(e.Result);
$.getJSON("http://localhost/Backbone.Todo/todos", function(todos) {
alert(todos.length == 1);
});


That's all the application code required to create a simple web service.
That's all the application code required to create a simple REST web service.

##Live Demo of Backbone TODO app (running on Linux/MONO):

**[http://www.servicestack.net/Backbone.Todos/](http://www.servicestack.net/Backbone.Todos/)**

Preview links using just the above code sample with (live demo running on Linux):
[XML](http://www.servicestack.net/ServiceStack.Examples.Host.Web/ServiceStack/Xml/SyncReply/GetFactorial?ForNumber=3),
[JSON](http://www.servicestack.net/ServiceStack.Examples.Host.Web/ServiceStack/Json/SyncReply/GetFactorial?ForNumber=3),
[JSV](http://www.servicestack.net/ServiceStack.Examples.Host.Web/ServiceStack/Jsv/SyncReply/GetFactorial?ForNumber=3&debug)
Check out the [live demo](http://www.servicestack.net/ServiceStack.Examples.Clients/) with
[full source code](http://code.google.com/p/servicestack/source/browse/#svn/trunk/ServiceStack.Examples).

* [XML](http://www.servicestack.net/Backbone.Todos/todos?format=xml),
* [JSON](http://www.servicestack.net/Backbone.Todos/todos?format=json)
* [HTML](http://www.servicestack.net/Backbone.Todos/todos?format=html)
* [JSV](http://www.servicestack.net/Backbone.Todos/todos?format=jsv)
* [CSV](http://www.servicestack.net/Backbone.Todos/todos?format=csv)


Download
Expand Down
Binary file modified lib/ServiceStack.Text.dll
Binary file not shown.
Binary file modified lib/tests/ServiceStack.Common.dll
Binary file not shown.
Binary file modified lib/tests/ServiceStack.Interfaces.dll
Binary file not shown.
Binary file modified lib/tests/ServiceStack.Redis.dll
Binary file not shown.
Binary file modified lib/tests/ServiceStack.Redis.pdb
Binary file not shown.
Binary file modified lib/tests/ServiceStack.Text.dll
Binary file not shown.
Binary file modified release/latest/ServiceStack.Interfaces.dll
Binary file not shown.
Binary file modified release/latest/ServiceStack.Redis/ServiceStack.Redis.dll
Binary file not shown.
Binary file modified release/latest/ServiceStack.dll
Binary file not shown.
Expand Up @@ -55,9 +55,13 @@ public interface IRedisTypedClient<T>
long IncrementValue(string key);
long IncrementValueBy(string key, int count);
long DecrementValue(string key);
long DecrementValueBy(string key, int count);
long DecrementValueBy(string key, int count);

bool ExpireIn(object id, TimeSpan expiresAt);
bool ExpireAt(object id, DateTime dateTime);
bool ExpireEntryIn(string key, TimeSpan expiresAt);
bool ExpireEntryAt(string key, DateTime dateTime);
bool ExpireEntryAt(string key, DateTime dateTime);

TimeSpan GetTimeToLive(string key);
void Save();
void SaveAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceStack/Properties/AssemblyInfo.cs
Expand Up @@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.7.*")]
[assembly: AssemblyVersion("2.0.8.*")]
//[assembly: AssemblyFileVersion("1.0.*")]
2 changes: 1 addition & 1 deletion src/ServiceStack/WebHost.EndPoints/Formats/HtmlFormat.cs
Expand Up @@ -271,7 +271,7 @@ TD DL
</div>
<script>!window.JSON && document.write(unescape('%3Cscript src=""https://github.com/douglascrockford/JSON-js/raw/master/json2.js""%3E%3C/script%3E'))</script>
<script>!window.JSON && document.write(unescape('%3Cscript src=""http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js""%3E%3C/script%3E'))</script>
<script type=""text/javascript"">
// <![CDATA[
Expand Down

0 comments on commit e45391d

Please sign in to comment.