Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Using only ServiceStack for web and web services</h2> <h3>ServiceStack's new Razor View Engine support</h3> <p>A significant improvement to ServiceStack's HTML story was added in <strong>v3.9.11</strong> in the <a href="https://nuget.org/packages/ServiceStack.Razor" rel="nofollow noreferrer">ServiceStack.Razor NuGet package</a>. With this support ServiceStack now graduates to a full Website and Web Services framework that offers a much simpler replacement to WCF, MVC and WebApi.</p> <p>Full documentation explaining ServiceStack's new HTML story with Razor Support is maintained in the <a href="https://github.com/ServiceStack/RazorRockstars/" rel="nofollow noreferrer">Razor Rockstars</a> demo website:</p> <ul> <li><a href="http://razor.servicestack.net" rel="nofollow noreferrer">http://razor.servicestack.net</a> - ASP.NET Host developed on Win hosted on Linux</li> <li><a href="http://razor-console.servicestack.net" rel="nofollow noreferrer">http://razor-console.servicestack.net</a> - Stand-alone Self Host developed on Win hosted on Linux</li> </ul> <p>Full Documentation explaining Razor support and describing its Features is explained in the links above.</p> <h3>Just a REST Service framework with HTML Format</h3> <p>The HTML Content-Type has been added to ServiceStack just as you would expect from a true REST Service framework, i.e. you can simply add Razor Views to enhance your existing services which will only get used when the client requests for the <code>text/html</code> Content-Type (with no effect on the existing registered formats). E.g. this <a href="http://razor.servicestack.net/rockstars" rel="nofollow noreferrer">/rockstars</a> REST service can still be accessed in all the other Content-Types: </p> <ul> <li><a href="http://razor.servicestack.net/rockstars?format=html" rel="nofollow noreferrer">HTML</a></li> <li><a href="http://razor.servicestack.net/rockstars?format=json" rel="nofollow noreferrer">JSON</a></li> <li><a href="http://razor.servicestack.net/rockstars?format=xml" rel="nofollow noreferrer">XML</a></li> <li><a href="http://razor.servicestack.net/rockstars?format=csv" rel="nofollow noreferrer">CSV</a></li> <li><a href="http://razor.servicestack.net/rockstars?format=jsv" rel="nofollow noreferrer">JSV</a></li> </ul> <p>In addition if your services has the <code>[ClientCanSwapTemplates]</code> attribute, the client can swap the Views and Templates of pages at runtime, e.g. here's the same above page with:</p> <ul> <li><a href="http://razor.servicestack.net/rockstars?View=AngularJS" rel="nofollow noreferrer">A Single Page AngularJS App with Client-side rendering</a></li> <li><a href="http://razor.servicestack.net/rockstars?Template=SimpleLayout" rel="nofollow noreferrer">A different SimpleLayout template</a></li> <li><a href="http://razor.servicestack.net/rockstars?View=AngularJS&amp;Template=SimpleLayout" rel="nofollow noreferrer">AngularJS with SimpleLayout template</a></li> </ul> <p>ServiceStack's natural adoption of the HTML format in this way, makes it trivial to develop 1 set of services that can serve both HTML and rich native mobile and desktop clients.</p> <h3>Other ways to serve HTML</h3> <p>Before Razor support was added there are a couple of strategies of serving HTML pages with ServiceStack:</p> <h3>Use a static html page with ajax calls</h3> <p>If you make a web request for an existing file, it gets returned with the Static File Handler. You can then simply make ajax json calls back to your web services to dynamically generate a page.</p> <p>The TODO Backbone application in the <a href="https://github.com/ServiceStack/ServiceStack.Examples/tree/master/src/StarterTemplates/WinServiceAppHost" rel="nofollow noreferrer">Windows Service AppHost Starter Template</a> works this way. (as well as most other example projects in ServiceStack :-)</p> <h3>Return a string</h3> <p>Any <strong>string</strong> returned from your web services gets directly written to the response stream 'as-is', so you can simply return html using your own html templating solution. </p> <p>Here's a list of <a href="https://stackoverflow.com/questions/6245616/does-servicestack-support-binary-responses">other possible return types</a> in ServiceStack and how they're treated.</p> <h2>Using Markdown Razor</h2> <p>The view-engine built into ServiceStack is <a href="http://www.servicestack.net/docs/markdown/markdown-razor" rel="nofollow noreferrer">Markdown Razor</a> - Which was inspired by MVC's Razor but using Markdown syntax. It's quite extensible supporting custom base class and extension methods/utils.</p> <p>A nice feature of using Markdown Razor is your same web service that returns json,xml, etc can also be a view model for a dynamically generated html page at the same url.</p> <p>An example of this is the <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/Docs/Docs.Logic/CategoryService.cs" rel="nofollow noreferrer">category web service</a> which you can see the results of here: <a href="http://www.servicestack.net/docs/category/Framework" rel="nofollow noreferrer">http://www.servicestack.net/docs/category/Framework</a></p> <p>and the same service again in <a href="http://www.servicestack.net/docs/category/Framework?format=json" rel="nofollow noreferrer">JSON</a>, <a href="http://www.servicestack.net/docs/category/Framework?format=xml" rel="nofollow noreferrer">XML</a>, etc. You can also retrieve the <a href="http://www.servicestack.net/docs/category/Framework?format=html.bare" rel="nofollow noreferrer">partially generated html page</a> (without the template) as well the <a href="http://www.servicestack.net/docs/category/Framework?format=text.bare" rel="nofollow noreferrer">dynamically generated markdown</a>.</p> <p>The page was created using the web services DTO/view model which was sent to this MarkdownRazor View <a href="https://raw.github.com/ServiceStack/ServiceStack.Examples/master/src/Docs/Views/Category.md" rel="nofollow noreferrer">https://raw.github.com/ServiceStack/ServiceStack.Examples/master/src/Docs/Views/Category.md</a></p> <p>If you have specified a Markdown Razor page for your web service, it is used over the default <a href="https://github.com/ServiceStack/ServiceStack/wiki/HTML5ReportFormat" rel="nofollow noreferrer">HTML5 JSON Report</a> that you see now. </p> <p>The resolution order ServiceStack's uses to resolve the appropriate Markdown template to use for rendering HTML output is:</p> <ul> <li>If the Web Service specifies a template (via a customized IHttpResult.TemplateName response) - then a View with that name.</li> <li>A view with the same name as the Response DTO, looking first in /Views then in /Views/Shared</li> <li>A view with the same name as the Request DTO, looking first in /Views then in /Views/Shared</li> </ul> <h2>Host ServiceStack at a /custompath</h2> <p>ServiceStack can be used together with or without an existing ASP.NET web application. If your application is <strong>HTML-heavy</strong> and <strong>REST-Services-light</strong> a common approach is to host ServiceStack at a <a href="http://www.servicestack.net/ServiceStack.Hello/#custompath" rel="nofollow noreferrer">/custompath</a> (e.g. /api) so you can use ASP.NET for all HTML page generation.</p> <p>If using ASP.NET MVC instead, you need to ignore the route in MVC's Global.asax <strong>RegisterRoutes()</strong>:</p> <pre><code>routes.IgnoreRoute ("servicestack/{*pathInfo}"); </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