ASP.NET Core REST API call throught WebSockets

Viewed 1628

Recently I talked with some developers, and they said that they call one endpoint from their front-end (web app) and that endpoint is a web socket. All their REST calls go through this connection. This solution was in Java. So I started wondering how they do that. How they dispatch the endpoint, what is the payload, etc. but in Asp.NET Core.

I am wondering is it possible and how.

3 Answers

I think you're mixing two different technologies.

A REST endpoint belongs to WebServices and is an url, pointing to one or more methods in your code that can accept parameters and return results in XML/JSON format.

You can then fetch this url from your front-end and read the response.

An example of REST webservice is Google Maps API.

A Websocket, instead, is a continuous connection and works as a plain socket but between a webpage running on a client and another server application on another machine (i.e. the server). It's used when you need an open tunnel with continuous exchange of data: chats, video and audio streaming, multiplayer games and more.

You cannot make a REST call to a websocket endpoint and if you want to use websockets you must write a server in C# (i use .net core). A console application.

I'm unsure what you are looking for exactly. If you want to start with websockets, this is where i started from:

Writing websocket server Writing a websocket server in C#

For webservices:

Writing a web service in ASP.NET

Related