The Northwind Web Services Example project explores different features of ServiceStack using data from Northwind SQlite Database.
ServiceStack's REST Services, are just normal Web Services with the addition of a [Route] attribute that allows you to provide the canonical / permanent location for your web service.
Path | Formats | Code | |
---|---|---|---|
All Customers | customers | jsonxmlhtmlcsvjsvx-vcard | CustomersService.cs |
Customer Maria Anders | customers/ALFKI | jsonxmlhtmlcsvjsvx-vcard | CustomerDetailsService.cs |
Customer Maria Anders Orders | customers/ALFKI/orders | jsonxmlhtmlcsvjsv | OrdersService.cs |
Latest Orders | orders | jsonxmlhtmlcsvjsv | OrdersService.cs |
Latest Orders - page 2 | orders/page/2 | jsonxmlhtmlcsvjsv | OrdersService.cs |
Northwind AutoQuery Services | |||
Customers | /query/customers | jsonxmlhtmlcsvjsv | AutoQuery.cs |
Countries Starting With 'U' | CountryStartsWith=U | jsonxmlhtmlcsvjsv | AutoQuery.cs |
Customers IN (CHOPS,FRANK) | Ids=CHOPS,FRANK | jsonxmlhtmlcsvjsv | AutoQuery.cs |
Orders | /query/orders | jsonxmlhtmlcsvjsv | AutoQuery.cs |
Freight more than $300 | Freight>=300 | jsonxmlhtmlcsvjsv | AutoQuery.cs |
Orders by Customer, Id Desc | OrderBy=CustomerId,-Id | jsonxmlhtmlcsvjsv | AutoQuery.cs |
AutoQuery UI for Northwind Services |
The entire datasource for the Northwind project is contained in this Northwind.sqlite database created by this unit test.
The Northwind database also includes the addition of the VCard custom media format.
Checkout the walk thru to see how to create your own Custom Media Types with ServiceStack:
As it's important for high-performance web services, ServiceStack includes a rich caching provider framework with Memory, Redis and RDBMS caching providers available.
To compare the difference with caching enabled, below are the 'cached versions' of the REST services above.
Path | Formats | Code | |
---|---|---|---|
All Customers | cached/customers | jsonxmlhtmlcsvjsv | CachedServices.cs |
Customer Maria Anders | cached/customers/ALFKI | jsonxmlhtmlcsvjsv | CachedServices.cs |
Customer Maria Anders Orders | cached/customers/ALFKI/orders | jsonxmlhtmlcsvjsv | CachedServices.cs |
Latest Orders | cached/orders | jsonxmlhtmlcsvjsv | CachedServices.cs |
Latest Orders - page 2 | cached/orders/page/2 | jsonxmlhtmlcsvjsv | CachedServices.cs |
Note: The most optimal result is cached, i.e. if your browser supports gzip/deflate it will cache the compressed output. Caching also supports all user-defined formats.
The Northwind project is also an example of how much can be achieved with a minimal amount of effort and code. This entire website literally just consists of these three classes . Everything else seen here is automatically provided by ServiceStack using a code-first, convention-based approach. ServiceStack can infer a richer intelligence about your services to better able to provide more generic and re-usable functionality for free!
You're unlikley to ever see the same WCF SOAP service, generating a visually informative HTML view of your data, allow it to be exposed over REST-ful interfaces or be able to export it to a CSV data file. With ServiceStack not only is this possible - it comes out-of-the-box, config-pain-free :)
No other config, code-gen are required and you do not need to learn any other artificial constructs and concepts to get started. The logic of your services simply live in a pure C#, dependency-free and testable class.
The initial difficulty to new developers coming to ServiceStack is having to un-learn WCFs RPC approach to web services. In our opinion the problem with WCF is not that it's an abstract walled-interface forcing you to develop all your Network services in.
The main problem is it forcing all network requests to marshal onto a C# method, we believe is an un-natural fit, leading to the creation of slow, chatty APIs. ServiceStack believes this is an anti-pattern which produces more friction then its preferred strong-typed DTO approach.