Skip to content

bowbahdoe/jdk-httpserver-realworld

Repository files navigation

RealWorld Example App

JDK HTTP Server codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

This codebase was created to demonstrate a fully fledged fullstack application built with the JDK HTTP Server including CRUD operations, authentication, routing, pagination, and more.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

This is deployed here

How it works

This is built up of a few components. Primarily

  • The jdk.httpserver module which provides the API that is programmed against
  • Jetty which provides the actual backing implementation for jdk.httpserver
  • Postgresql for the database
  • RainbowGum for logging

Then, serving specific tasks:

Almost all the code is contained in the RealWorldAPI class. If any of the choices made here offend your sensibilities I encourage forking and showing the way you would prefer it be done. If you think something is done in a subpar way or is otherwise objectively broken please open an issue.

Specifically, I would encourage folks to try and

  • Split up the RealWorldAPI class. Where are the natural boundaries?
  • Try using their database abstraction of choice. What would this look like with Hibernate, JOOQ, or JDBI? Would there be fewer or more round trips to the database?
  • Try using their JSON library of choice.
  • Try to do the whole persistence/service/etc. split. Does that make things better?
  • Add unit tests. For this exact thing there are already API tests I was able to just use, but how would testing look with JUnit?
  • etc.

I personally see a lot of areas for improvement once string templates are real. Counting ?s in big queries is maybe the biggest remaining "raw" JDBC shortcoming.

Getting started

Prerequisites

  • Java 22 or above
  • SDKMan
  • Docker

Usage

First, start up postgres

$ docker compose up -d

Then install MyBatis Migrations. This is currently easiest to do with SDKMan.

$ sdk install mybatis

Apply the migrations to the database

$ cd migrations
$ migrate up
$ cd ..

Then to run the server either

  • open the project in your editor
  • run it through maven (./mvnw exec:java -Dexec.mainClass="dev.mccue.jdk.httpserver.realworld.Main")
  • run it through docker
$ docker build -t realworld .
$ docker run realworld

The .env file for this project is committed to the repo. Note that in general this is a bad idea/practice, but the only secrets here are for the local database connection so it's fine.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages