Skip to content

AnthonyCarl/ServiceStack.PartialResponse

Repository files navigation

ServiceStack.PartialResponse.ServiceModel

Google Style Partial Responses for ServiceStack.Net. Currently only the following Content types are supported:

  • application/json
  • application/jsv
  • text/html

application/xml is NOT currently supported.

This is implemented as an IRequestContext extension. It can easily be incorporated into a ServiceStack plugin as part of the final processing of your response.

##Providing Field Selectors Field Selectors can be passed using the header or query string. By default field selectors are combined form both. Duplicate field selectors are reduced. The field selector is applied to all entries in a list if the selector refers to a list.

Method Example
Query String http://myhost/mydtoroute?fields=id&fields=todt or http://myhost/mydtoroute?fields=id,todt
Header x-fields: id,todt

If field selectors are passed in the query string, make sure it is properly encoded.

##Field Selector Reserved Characters

Character Meaning
, Separates multiple field selectors
/ Field sub selector
( Begin subselection expression
) End subselection expression

Currently * is not supported.

Note: All field selector reserved characters may be nested.

##Field Selector Examples

Example: person(name(first,last),address(zip,street)),person/salary,link(url,description/short)

Explanation: This will select the person's first and last name, their salary, and the zip and street portions of their address. It will also select the url and short description of the link.


Example: people/name/first

Explanation: people refers to a list. This will select the first name of all people in the list.

##Code Examples

public object Get(MyRequestDto request)
{
  MyResponseDto response = SomeMethodThatGeneratesTheResponse(request);
  return base.requestContext.ToPartialResponse(response)
}

--or, if you want it compressed--

public object Get(MyRequestDto request)
{
  MyResponseDto response = SomeMethodThatGeneratesTheResponse(request);
  return base.ToOptimizedResult(base.requestContext.ToPartialResponse(response))
}

##Basic Benchmark

The DTO used contains 32 properties. The response is a list of 250 of these DTOs. The partial response only selects one integer property.

===================================
Completed 1000 Test Iterations
===================================

===================================
Partial Response min/max/avg 12ms/323ms/15.208ms
===================================
Full Response min/max/avg 18ms/383ms/25.624ms
===================================

##Using the Code

  • Install the NuGet Package
  • NuGet Packages from Latest Successful Build
  • You can check out the code and run build.bat.
    • It will create NuGet packages you can consume in .\ReleasePackages or you can directly use the resulting binaries.
    • If you use a custom made NuGet package and have an internal symbol server, you may be interested in the IndexSrc build target to properly index the source code back to GitHub.
  • Build requirements
    • .Net 4.0
    • Powershell 2.0

##ToDo

  • Publish Code for Client Side support. I have working strongly typed implementation (using expression trees) but it needs to be cleaned up for release.

##Release Notes CodeBetter CI

Special Thanks to JetBrains and CodeBetter for hosting this project!

About

Google Style Partial Responses for ServiceStack.Net

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published