title | description | author | ms.service | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|
Quickstart - Azure SignalR Service REST API |
A quickstart for using the Azure SignalR Service REST API. |
sffamily |
signalr |
quickstart |
03/01/2019 |
zhshang |
Azure SignalR Service provides REST API to support server to client communication scenarios, such as broadcasting. You can choose any programming language that can make REST API call. You can post messages to all connected clients, a specific client by name, or a group of clients.
In this quickstart, you will learn how to send messages from a command-line app to connected client apps in C#.
This quickstart can be run on macOS, Windows, or Linux.
- .NET Core SDK
- A text editor or code editor of your choice.
[!INCLUDE quickstarts-free-trial-note]
Sign in to the Azure portal at https://portal.azure.com/ with your Azure account.
[!INCLUDE Create instance]
While the service is deploying, let's switch to prepare the code. Clone the sample app from GitHub, set the SignalR Service connection string, and run the application locally.
-
Open a git terminal window. Change to a folder where you want to clone the sample project.
-
Run the following command to clone the sample repository. This command creates a copy of the sample app on your computer.
git clone https://github.com/aspnet/AzureSignalR-samples.git
This sample is a console app showing the use of Azure SignalR Service. It provides two modes:
- Server Mode: use simple commands to call Azure SignalR Service REST API.
- Client Mode: connect to Azure SignalR Service and receive messages from server.
Also you can find how to generate an access token to authenticate with Azure SignalR Service.
We use macOS osx.10.13-x64 as example. You can find reference on how to build on other platforms.
cd AzureSignalR-samples/samples/Serverless/
dotnet publish -c Release -r osx.10.13-x64
cd bin/Release/netcoreapp2.1/osx.10.13-x64/
Serverless client <ClientName> -c "<ConnectionString>" -h <HubName>
cd bin/Release/netcoreapp2.1/osx.10.13-x64/
Serverless server -c "<ConnectionString>" -h <HubName>
You can also run the command below to start a server or client
# Start a server
dotnet run -- server -c "<ConnectionString>" -h <HubName>
# Start a client
dotnet run -- client <ClientName> -c "<ConnectionString>" -h <HubName>
You can run dotnet user-secrets set Azure:SignalR:ConnectionString "<ConnectionString>"
in the root directory of the sample. After that, you don't need the option -c "<ConnectionString>"
anymore.
After the server started, use the command to send message:
send user <User Id>
send users <User List>
send group <Group Name>
send groups <Group List>
broadcast
You can start multiple clients with different client names.
The Azure SignalR service allows third-party services to integrate with the system.
The following table shows all the versions of the REST APIs supported to date. You can also find the definition file for each specific version
Version | API State | Door | Specific |
---|---|---|---|
1.0-preview |
Available | 5002 | Swagger |
1.0 |
Available | Standard | Swagger |
The list of available APIs for each specific version is available in the following list.
API | 1.0-preview |
1.0 |
---|---|---|
Broadcast to all | ✓ | ✓ |
Broadcast to a group | ✓ | ✓ |
Broadcast to some groups | ✓ (Deprecated) | N / A |
Send to specific users | ✓ | ✓ |
Send to some users | ✓ (Deprecated) | N / A |
Adding a user to a group | N / A |
✓ |
Removing a user from a group | N / A |
✓ |
Version | API HTTP Method | Request URL | Request body |
---|---|---|---|
1.0-preview |
POST |
https://<instance-name>.service.signalr.net:5002/api/v1-preview/hub/<hub-name> |
{"target": "<method-name>", "arguments": [...]} |
1.0 |
POST |
https://<instance-name>.service.signalr.net/api/v1/hubs/<hub-name> |
Same as above |
Version | API HTTP Method | Request URL | Request body |
---|---|---|---|
1.0-preview |
POST |
https://<instance-name>.service.signalr.net:5002/api/v1-preview/hub/<hub-name>/group/<group-name> |
{"target": "<method-name>", "arguments": [...]} |
1.0 |
POST |
https://<instance-name>.service.signalr.net/api/v1/hubs/<hub-name>/groups/<group-name> |
Same as above |
Version | API HTTP Method | Request URL | Request body |
---|---|---|---|
1.0-preview |
POST |
https://<instance-name>.service.signalr.net:5002/api/v1-preview/hub/<hub-name>/user/<user-id> |
{"target": "<method-name>", "arguments": [...]} |
1.0 |
POST |
https://<instance-name>.service.signalr.net/api/v1/hubs/<hub-name>/users/<user-id> |
Same as above |
Version | API HTTP Method | Request URL |
---|---|---|
1.0 |
PUT |
https://<instance-name>.service.signalr.net/api/v1/hubs/<hub-name>/groups/<group-name>/users/<userid> |
Version | API HTTP Method | Request URL |
---|---|---|
1.0 |
DELETE |
https://<instance-name>.service.signalr.net/api/v1/hubs/<hub-name>/groups/<group-name>/users/<userid> |
[!INCLUDE Cleanup]
In this quickstart, you learned how to use REST API to broadcast real-time message from SignalR Service to clients. Next, learn more about how to develop and deploy Azure Functions with SignalR Service binding, which is built on top of REST API.
[!div class="nextstepaction"] Develop Azure Functions using Azure SignalR Service bindings