You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-41Lines changed: 65 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,58 +6,82 @@ Service Stack is a high-performance .NET web services framework _(including a nu
6
6
that simplifies the development of XML, JSON, JSV and WCF SOAP [Web Services](https://github.com/ServiceStack/ServiceStack/wiki/Service-Stack-Web-Services).
7
7
For more info check out [servicestack.net](http://www.servicestack.net).
8
8
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
+
}
39
48
40
49
### Calling the factorial service from any C#/.NET Client
41
50
//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");
0 commit comments