Front-end with Uniscale SDK
On this page, you will learn how to use the SDK with your front-end application.
This tutorial uses Uniscale's Message Threads demo solution as its base. For more detailed information on the SDK, see Library implementation
Installation
You can find the correct SDK information in your solution or service's SDK Portal in Uniscale.
Configure registry
Install SDK
Tutorial: Using the SDK with your front-end application
Following this tutorial will help you set up a dispatcher for handling requests that communicate with the endpoints provided in the specification. A similar approach is used in this demo project: https://github.com/uniscale/demo-ts-frontend
Step 1: Implement the dispatcher
This function will return a dispatcher which can then be used to handle any communication with the endpoints. Depending on the structure of your front-end application, you can also implement the same functionality into a dispatcher class.
asSolution
asSolution
You can acquire a DispatcherSession by calling the session with asSolution
using your solution identifier. When you have the dispatcher session, you are ready to call your endpoints. You can find your solution identifier in your solution's SDK Portal in Uniscale.
withLocale
withLocale
If your service has different translations for i.e. error codes, you can define the locale you wish to use.
withDataTenant
withDataTenant
If you have a multitenant environment, you can specify the required identifier here.
Step 2: Add interceptors
These are interceptors that will call the service. The sample uses pattern interceptors to intercept all features defined below that pattern in the model. This makes it easier if you have multiple services using the same solution SDK.
To use the endpoints, we make a POST
call on the correct URL and pass it a serialized GatewayRequest
as defined in the SDK. The response also needs to be serialized into the Result
class.
Step 3: Using the dispatcher
At the base of your application, call your initialize function to get the dispatcher:
After this, you can use endpoints to fetch your data:
Tutorial: Using sample data from the SDK
If you want to use the endpoints provided by the SDK but don't yet have a working backend, you can register message interceptors in your dispatcher to return sample data instead of calling the real service.
Step 1: Add mock interceptors to the dispatcher
You can either add your own mock data here or use sample data provided by the SDK.
Step 2: Call the endpoint
The endpoint now returns the mock data returned by your interceptor. When you have a working service, you can just remove the mock interceptor from your dispatcher.
Last updated