Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API with websocket using Spring boot

I am actually working to my university junior project.
I want to make a game using spring boot, this game will need a WebSocket.
I will surely need to make a REST API for user registration, deleting, updating, posting and getting data.

Am I going to be able to use WebSocket along with REST?
If yes please send me resources that can help me, otherwise please tell me what should I do.
I'm sorry if my question was not so smart but I am new to all of this.

like image 664
Omar Shrbaji Avatar asked Nov 06 '17 18:11

Omar Shrbaji


People also ask

Can you use WebSockets with REST API?

REST is the most commonly used architecture for developing APIs in recent years. It supports a half-duplex data transmission between the client and server. In the case of full-duplex data transmission, WebSockets are used.

Does Spring boot support WebSocket?

Starting with version 4.1, Spring Integration has WebSocket support. It is based on the architecture, infrastructure, and API from the Spring Framework's web-socket module.

Should I use WebSockets or REST API?

WebSocket is ideal for a scenario where high loads are a part of the game, i.e. real-time scalable chat application, whereas REST is better fitted for occasional communication in a typical GET request scenario to call RESTful APIs.


1 Answers

Yes, your Spring application can easily use both WebSocket and REST APIs. If you're going to use Spring Boot, I'd suggest to take a look into their example projects (note the spring-boot-sample-websocket- directories). I think it's the best way to learn.

More on WebSockets, I'd suggest to use STOMP protocol. There is also a nice guide for it on how you can get started.

For your RESTful API, you'll be making simple controllers / services, there is tones of resources for this. You can also follow this guide to get started as well.

like image 168
Edd Avatar answered Oct 08 '22 05:10

Edd