Websockets support?

Open
#147 5 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
java
Domain
api, backend

Research direction

The issue names no repository files or tests; its concrete entry-point reference is Javalin's ApiBuilder, alongside Spring and Helidon websocket examples. Start by reviewing the existing controller and server integration, then determine whether the project should add websocket support or a separate library. Done criteria are not defined in the issue.

Written by the indexing model from the issue text.

Description

Could we see some kind of websocket support here or in a seperate avaje-sockets library? It would be nice to be able to have a Spring-like system for them too, in a glimpse I see this guide from Spring with the following sample:

(...)
@Controller
public class GreetingController {

  @MessageMapping("/hello")
  @SendTo("/topic/greetings")
  public Greeting greeting(HelloMessage message) throws Exception {
    Thread.sleep(1000); // simulated delay
    return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
  }
}

This controller is concise and simple, but plenty is going on. We break it down step by step.

The @MessageMapping annotation ensures that, if a message is sent to the /hello destination, the greeting() method is called.

The payload of the message is bound to a HelloMessage object, which is passed into greeting().

Internally, the implementation of the method simulates a processing delay by causing the thread to sleep for one second. This is to demonstrate that, after the client sends a message, the server can take as long as it needs to asynchronously process the message. The client can continue with whatever work it needs to do without waiting for the response.

After the one-second delay, the greeting() method creates a Greeting object and returns it. The return value is broadcast to all subscribers of /topic/greetings, as specified in the @SendTo annotation. Note that the name from the input message is sanitized, since, in this case, it will be echoed back and re-rendered in the browser DOM on the client side.

This is a pretty beautiful system, but obviously as all things Spring is bloated, and Javalin (and Heildon actually, I've personally zero experience with Heildon so I'm probably stating things you're already aware of) already provides support for websockets.
Javalin has websocket registration right inside of ApiBuilder and I imagine Heildon has a simple system to do so as well, so it shouldn't be too much work to get this to work.

Dominant language
Java
Stars
99
Forks
19
Avg merge
14h 26m
Merged PRs (30d)
12

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from avaje/avaje-http

All issues in avaje/avaje-http

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.