Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In addition to specifying it on the QueryString with <strong>?format=json</strong>, <a href="https://github.com/ServiceStack/ServiceStack/wiki/Routing#content-negotiation" rel="noreferrer">by appending the format</a> <strong>.ext</strong> to the end of the route, e.g: <a href="http://razor.servicestack.net/rockstars.json" rel="noreferrer">/rockstars.json</a>, or by specifying the HTTP Header (in your HttpClient): <code>Accept: application/json</code>.</p> <p>Otherwise if your HttpClient doesn't send an Accept header you can specify JSON as the default content type in your AppHost with:</p> <pre><code>SetConfig(new HostConfig { DefaultContentType = MimeTypes.Json }); </code></pre> <p>All Configuration options in ServiceStack are set here.</p> <p>The issue when calling web services from a web browser is that they typically ask for <code>Accept: text/html</code> and not JSON which by contract ServiceStack obliges by returning back HTML if it is enabled.</p> <p>To ensure JSON is returned you may also want to disable the HTML feature with:</p> <pre><code>SetConfig(new HostConfig { EnableFeatures = Feature.All.Remove(Feature.Html), }); </code></pre> <h2>Different ways to specify the Response Content Type</h2> <p>Otherwise if you want to override the Accept header you can force your service to always return json with any of these ways to <a href="https://github.com/ServiceStack/ServiceStack/wiki/Customize-HTTP-Responses" rel="noreferrer">Customize the HTTP Response</a>, e.g:</p> <p>Using a filter (AddHeader is built-in):</p> <pre><code>[AddHeader(ContentType=MimeTypes.Json)] public object Any(Request request) { ... } </code></pre> <p>Setting the Response in the service:</p> <pre><code>public object Any(Request request) { base.Response.ContentType = MimeTypes.Json; return dto; } </code></pre> <p>Returning a decorated response:</p> <pre><code>return new HttpResult(dto, MimeTypes.Json); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload