Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active August 11, 2016 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/363605c3c121784ebababac4a03e8910 to your computer and use it in GitHub Desktop.
Save gistlyn/363605c3c121784ebababac4a03e8910 to your computer and use it in GitHub Desktop.
Add ServiceStack Reference

Add ServiceStack Reference is ServiceStack's feature integrating with most major IDE's for generating typed DTO's from the URL of a remote ServiceStack instance so they can be easily consumed from C#, TypeScript, Swift, Java, Kotlin, F# and VB.NET Mobile, Desktop and Web Apps. The integrated support in Gistlyn extends their reach even further where anyone with just a modern web browser on their Desktop or iPad can add a typed reference and explore your ServiceStack Services using C# and LINQ in seconds.

Add a ServiceStack Reference via Url

The fastest way for your Customers quickly try out your Services is to send them a URL with your BaseUrl appended to the ?AddServiceStackReference query string, e.g:

This will instruct Gistlyn to immediately popup the Add ServiceStack Reference dialog with the BaseUrl provided and automatically verify it's of a valid ServiceStack instance:

Then after hitting Enter (or clicking the Add Reference button) Gistlyn will create a new Gist with the appropriate packages.config NuGet references, Typed DTO's and a main.cs populated with a JsonServiceClient containing the BaseUrl that's ready to execute:

var client = new JsonServiceClient("http://techstacks.io");

//Call techstacks.io APIs by sending typed Request DTO's
var response = client.Get(new GetAllTechnologies {  });

//response.PrintDump();  // Uncomment to Print Response to Console

Enhanced URL Options

By default Gistlyn will use the first GET Request DTO it can find, but you can specify which Request DTO it should use with the ?Request query string, e.g:

You can also tell Gistlyn what to populate the C# Expression Evaluator with the ?expression query string:

And tell Gistlyn to automatically execute the populated Gist with the ?autorun=1 query string.

Altogether this lets you send your Customers a URL to create a new Gist with a reference to your Services Typed DTO's, populate it with your desired Request DTO and expression and have it automatically run within seconds.

E.g. the link below will call techstacks.io public API and return details of the current Top Technology:

Add a ServiceStack Reference to your Gist

Following the same UX as supported IDE's, you can use Gistlyn's Editor popup menu to Add ServiceStack Reference to your current Gist:

This will open a popup to add the BaseUrl of the remote ServiceStack instance you want to generate typed DTO's for:

If this is a valid URL to a ServiceStack instance Gistlyn will enable the Add Reference button you can press to add the Typed DTO's to your Gist in the filename specified:

As Roslyn's C# Scripting doesn't allow namespaces, if you're referencing a ServiceStack instance prior to v4.0.62 you'll need to manually strip the C# namespaces.

Gistlyn will also add the necessary ServiceStack.Client NuGet package references to your packages.config:

With the typed C# DTO's and ServiceStack.Client NuGet package now available to your Gist, you can now call Services by sending Request DTO's to the appropriate JsonServiceClient method, e.g:

var client = new JsonServiceClient(baseUrl);
var response = client.Get(new MyRequest { });

The top-level response variable can be further inspected using the Property Viewer and C# Expression evaluator on the right:

An alternative way to quickly view a Services response is to use ServiceStack.Text's PrintDump() extension method to dump a pretty-print view of any POCO to Gistlyn's Console:

response.PrintDump();

Using Alt+c to open Gistlyn's Console Viewer:

Human Friendly short URLs

In addition to the manually constructed URLs above, you can also request to have easier to remember URLs for links to any Gistlyn gists, collections or Add ServiceStack Reference URLs by leaving a comment on the Friendly Names Gist

Where any link in the above Gist are available to Gistlyn, so instead of sending the long ?AddServiceStackReference URL above, you can instead send the shorter and more descriptive:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment