Skip to content

Commit e45391d

Browse files
committed
Added v2.08 libs, updated README.md to include Backbone rest service instead
1 parent a517811 commit e45391d

13 files changed

Lines changed: 73 additions & 45 deletions

File tree

README.md

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,82 @@ Service Stack is a high-performance .NET web services framework _(including a nu
66
that simplifies the development of XML, JSON, JSV and WCF SOAP [Web Services](https://github.com/ServiceStack/ServiceStack/wiki/Service-Stack-Web-Services).
77
For more info check out [servicestack.net](http://www.servicestack.net).
88

9-
Simple web service example
10-
==========================
11-
12-
[DataContract]
13-
[RestService("/factorial/{ForNumber}")]
14-
public class GetFactorial
15-
{
16-
[DataMember]
17-
public long ForNumber { get; set; }
18-
}
19-
20-
[DataContract]
21-
public class GetFactorialResponse
22-
{
23-
[DataMember]
24-
public long Result { get; set; }
25-
}
26-
27-
public class GetFactorialService : IService<GetFactorial>
28-
{
29-
public object Execute(GetFactorial request)
30-
{
31-
return new GetFactorialResponse { Result = GetFactorial(request.ForNumber) };
32-
}
33-
34-
static long GetFactorial(long n)
35-
{
36-
return n > 1 ? n * GetFactorial(n - 1) : 1;
37-
}
38-
}
9+
Simple REST service example
10+
===========================
11+
12+
//Register REST Paths
13+
[RestService("/todos")]
14+
[RestService("/todos/{Id}")]
15+
public class Todo //REST Resource DTO
16+
{
17+
public long Id { get; set; }
18+
public string Content { get; set; }
19+
public int Order { get; set; }
20+
public bool Done { get; set; }
21+
}
22+
23+
//Todo REST Service implementation
24+
public class TodoService : RestServiceBase<Todo>
25+
{
26+
public TodoRepository Repository { get; set; } //Injected by IOC
27+
28+
public override object OnGet(Todo request)
29+
{
30+
if (request.Id == default(long))
31+
return Repository.GetAll();
32+
33+
return Repository.GetById(request.Id);
34+
}
35+
36+
//Called for new and update
37+
public override object OnPost(Todo todo)
38+
{
39+
return Repository.Store(todo);
40+
}
41+
42+
public override object OnDelete(Todo request)
43+
{
44+
Repository.DeleteById(request.Id);
45+
return null;
46+
}
47+
}
3948

4049
### Calling the factorial service from any C#/.NET Client
4150
//no code-gen required, can re-use above DTO's
42-
var serviceClient = new JsonServiceClient("http://localhost/myservice/");
43-
var response = serviceClient.Get<GetFactorialResponse>("factorial/3");
44-
Console.WriteLine("Result: {0}", response.Result);
51+
52+
var restClient = new JsonServiceClient("http://localhost/Backbone.Todo");
53+
var all = restClient.Get<List<Todo>>("/todos"); // Count = 0
54+
55+
var todo = restClient.Post<Todo>("/todos", new Todo { Content = "New TODO", Order = 1 }); //todo.Id = 1
56+
all = restClient.Get<List<Todo>>("/todos"); // Count = 1
57+
58+
todo.Content = "Updated TODO";
59+
todo = restClient.Post<Todo>("/todos", todo); // todo.Content = Updated TODO
60+
61+
restClient.Delete<Todo>("/todos/" + todo.Id);
62+
all = restClient.Get<List<Todo>>("/todos"); // Count = 0
63+
4564

4665
### Calling the factorial service from jQuery
4766

48-
$.getJSON("http://localhost/myservice/factorial/3", function(e) {
49-
alert(e.Result);
67+
$.getJSON("http://localhost/Backbone.Todo/todos", function(todos) {
68+
alert(todos.length == 1);
5069
});
5170

5271

53-
That's all the application code required to create a simple web service.
72+
That's all the application code required to create a simple REST web service.
73+
74+
##Live Demo of Backbone TODO app (running on Linux/MONO):
75+
76+
**[http://www.servicestack.net/Backbone.Todos/](http://www.servicestack.net/Backbone.Todos/)**
5477

5578
Preview links using just the above code sample with (live demo running on Linux):
56-
[XML](http://www.servicestack.net/ServiceStack.Examples.Host.Web/ServiceStack/Xml/SyncReply/GetFactorial?ForNumber=3),
57-
[JSON](http://www.servicestack.net/ServiceStack.Examples.Host.Web/ServiceStack/Json/SyncReply/GetFactorial?ForNumber=3),
58-
[JSV](http://www.servicestack.net/ServiceStack.Examples.Host.Web/ServiceStack/Jsv/SyncReply/GetFactorial?ForNumber=3&debug)
59-
Check out the [live demo](http://www.servicestack.net/ServiceStack.Examples.Clients/) with
60-
[full source code](http://code.google.com/p/servicestack/source/browse/#svn/trunk/ServiceStack.Examples).
79+
80+
* [XML](http://www.servicestack.net/Backbone.Todos/todos?format=xml),
81+
* [JSON](http://www.servicestack.net/Backbone.Todos/todos?format=json)
82+
* [HTML](http://www.servicestack.net/Backbone.Todos/todos?format=html)
83+
* [JSV](http://www.servicestack.net/Backbone.Todos/todos?format=jsv)
84+
* [CSV](http://www.servicestack.net/Backbone.Todos/todos?format=csv)
6185

6286

6387
Download

lib/ServiceStack.Text.dll

0 Bytes
Binary file not shown.

lib/tests/ServiceStack.Common.dll

2.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.

lib/tests/ServiceStack.Redis.dll

1.5 KB
Binary file not shown.

lib/tests/ServiceStack.Redis.pdb

2 KB
Binary file not shown.

lib/tests/ServiceStack.Text.dll

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
1.5 KB
Binary file not shown.

release/latest/ServiceStack.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)