Skip to content

Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all

License

Notifications You must be signed in to change notification settings

dylanvdmerwe/ServiceStack

 
 

Repository files navigation

Async/Awaitable Client Support

Xamarin now supports full async/await functionality from .NET 4.5 which allows for some amazing client-side code. ServiceStack libraries now support cross-platform awaitable operations!

  • Json
  • Jsv
  • Xml

Tested platforms:

  • Xamarin.iOS 7.0+
  • Xamarin.Android 4.8+
  • Windows Phone 8

Example usage:

        public async void TestAwaitPost()
        {
            JsonServiceClient client = new JsonServiceClient("http://localhost:82/");

            var request = new GetFactorial { ForNumber = 3 };
            GetFactorialResponse response = null;
            response = await client.PostAsync(request);
            Console.WriteLine(response.Result); // 6
        }

See www.servicestack.net for an overview.

Join the ServiceStack Google+ Community or follow @ServiceStack for project updates. You can also join a growing crowd of ServiceStack users on JabbR if you want to chat.

Service Stack is a high-performance .NET web services platform that simplifies the development of high-performance REST (JSON, XML, JSV, HTML, MsgPack, ProtoBuf, CSV) and WCF SOAP Web Services.

Simple REST service example

This example is also available as a stand-alone integration test:

//Web Service Host Configuration
public class AppHost : AppHostHttpListenerBase
{
    public AppHost() : base("TODOs Tests", typeof(Todo).Assembly) {}

    public override void Configure(Container container)
    {
        container.Register(new TodoRepository());
    }
}

//REST Resource DTO
[Route("/todos")]
[Route("/todos/{Ids}")]
public class Todos : IReturn<List<Todo>>
{
    public long[] Ids { get; set; }
    public Todos(params long[] ids)
    {
        this.Ids = ids;
    }
}

[Route("/todos", "POST")]
[Route("/todos/{Id}", "PUT")]
public class Todo : IReturn<Todo>
{
    public long Id { get; set; }
    public string Content { get; set; }
    public int Order { get; set; }
    public bool Done { get; set; }
}

public class TodosService : Service
{
    public TodoRepository Repository { get; set; }  //Injected by IOC

    public object Get(Todos request)
    {
        return request.Ids.IsEmpty()
            ? Repository.GetAll()
            : Repository.GetByIds(request.Ids);
    }

    public object Post(Todo todo)
    {
        return Repository.Store(todo);
    }

    public object Put(Todo todo)
    {
        return Repository.Store(todo);
    }

    public void Delete(Todos request)
    {
        Repository.DeleteByIds(request.Ids);
    }
}

Calling the above TODO REST service from any C#/.NET Client

//no code-gen required, can re-use above DTO's

var restClient = new JsonServiceClient(BaseUri);
List<Todo> all = restClient.Get(new Todos());     		// Count = 0

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

todo.Content = "Updated TODO";
todo = restClient.Put(todo);							// todo.Content = Updated TODO

restClient.Delete(new Todos(todo.Id));
all = restClient.Get(new Todos());						// Count = 0

Calling the TODO REST service from jQuery

$.getJSON(baseUri, function(todos) {
	alert(todos.length == 1);
});

Calling the TODO REST service from Dart JsonClient

var client = new JsonClient(baseUri);
client.todos()
	.then((todos) => alert(todos.length == 1) ); 

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

Getting Started

Download

If you have NuGet installed, the easiest way to get started is to install ServiceStack via NuGet:

ServiceStack with Razor Support: Create an empty ASP.NET Web or Console Application and (.NET 4.0+) Install-Pacakage ServiceStack.Razor2

ServiceStack binaries only: Minimal installation of ServiceStack containing only the core-binaries (.NET 3.5+) Install-Pacakage ServiceStack

Starter templates with pre-configured AppHost and basic Hello World REST services

If you just want ServiceStack hosted at / - Create an empty ASP.NET Web Application and Install-Pacakage ServiceStack.Host.Mvc

Otherwise if you want to host ServiceStack Side-by-Side with MVC: Hosted at /api - Create an empty MVC Web Application and Install-Pacakage ServiceStack.Host.Mvc

To help get started you should also clone the ServiceStack.Examples projects (includes dlls, demos and starter templates):

git clone git://github.com/ServiceStack/ServiceStack.Examples.git

Alternatively if you want keep up with the latest version and not use NuGet, simply clone this repo:

git clone git://github.com/ServiceStack/ServiceStack.git

Download published NuGet binaries without NuGet

GitHub has disabled its download feature so currently NuGet is the best way to get ServiceStack published releases. For environments that don't have NuGet installed (e.g. OSX/Linux) you can still download the published binaries by extracting them from the published NuGet packages. The url to download a nuget package is:

http://packages.nuget.org/api/v1/package/{PackageName}/{Version}

So to get the core ServiceStack and ServiceStack.Text libs in OSX/Linux (or using gnu tools for Windows) you can just do:

wget -O ServiceStack http://packages.nuget.org/api/v1/package/ServiceStack/3.9.56
unzip ServiceStack 'lib/*'

wget -O ServiceStack.Text http://packages.nuget.org/api/v1/package/ServiceStack.Text/3.9.56
unzip ServiceStack.Text 'lib/*'

which will download and extract the dlls into your local local lib/ folder.

Release notes for major releases

OSS Libraries used

ServiceStack includes source code of the great libraries below for some of its core functionality. Each library is released under its respective licence:

Similar open source projects

Similar Open source .NET projects for developing or accessing web services include:

  • Nancy Fx - A Sinatra-inspired lightweight Web Framework for .NET:
  • Fubu MVC - A "Front Controller" pattern-style MVC framework designed for use in web applications built on ASP.NET:
  • Rest Sharp - An open source REST client for .NET

Find out More

Follow @ServiceStack and +ServiceStack for project updates.


Core Team

Contributors

A big thanks to GitHub and all of ServiceStack's contributors:


Runs on both Mono and .NET 3.5. (Live preview hosted on Mono / CentOS)

About

Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 85.1%
  • JavaScript 10.9%
  • CSS 3.0%
  • Shell 0.3%
  • Pascal 0.3%
  • Classic ASP 0.3%
  • PowerShell 0.1%