Git Product home page Git Product logo

seij-jakarta-ws-rs-hateoas's Introduction

Jakarta RESTful Web Services (Jax-RS) HATEOAS extensions

Introduction

Project in active structuration, not ready for daily use

Check the Wiki for more details!

Goal

Write easily REST APIs with HATEOAS style with JAX-RS in JakartaEE (JavaEE) or Spring environments. Provide server and client support based on JAX-RS principles.

Why

  • You can do it manually but it's awful to write and error prone.
  • JaxRS only supports natively header links.
  • Spring Hateoas is ...meh, only supports Spring Webmvc, doesn't support Jax-RS
  • There is no easy client library

Sample code

Target code we want to reach. Shall autodetect annotations.

@Path("products")
@ResourceHateaos
class ProductsController {
    @GET
    @Path("{id}") @ResourceOperationGet
    @Produces(MediaTypeHateoas.APPLICATION_HAL_JSON)
    Product getById(@PathParam("id") String id) {  }

    @GET
    @Path("/") @ResourceOperationList
    @Produces(MediaTypeHateoas.APPLICATION_HAL_JSON)
    ResourceCollection<Product> list(ResourceCollectionFilter filter) {  }

    @POST
    @Path("{id}") @ResourceOperationOther("special")
    @Produces(MediaTypeHateoas.APPLICATION_HAL_JSON)
    Product special() {  }

}

Project provides tooling to do it manually

@GET
@Path("{id}")
@Produces(MediaTypeHateoas.APPLICATION_HAL_JSON)
public Response getById(@PathParam("id") UUID uid, @Context UriInfo uriInfo) {
    Link selfLink = Links.fromUriBuilder("self", uriInfo.getRequestUriBuilder()).rel("self").build();
    Link otherLink = Links.fromUriBuilder("operation1", uriInfo.getRequestUriBuilder()...).build();
    Link embeddedLink = Links.fromUriBuilder("operation2", ()-> getTheContentHere, uriInfo.getRequestUriBuilder()).build();
    return Response.ok(new EntityLinked<>(myobjectByUid, Arrays.asList(selfLink, otherLink, embeddedLink))).build();
}

Stories

Shall produce

  • simple links : "_links": { "operation": { "href": "..." }, ... }
  • embedded links : "_embedded": { "operation": { _operation_data_ }, ... }
  • extensions for OpenAPI documentation when using Eclipse Microprofile OpenAPI

Shall work using the following configurations

  • JavaEE 8 / JakartaEE (tests on Wildfly 17 + Resteasy + Jaxb)
  • JavaEE 8 / JakartaEE (tests on Wildfly 17 + Resteasy + Jackson)
  • Spring(-Boot) + Jackson + Resteasy
  • Spring(-Boot) + Jackson + Jersey
  • Java 8

Installation

Maven

: publish Maven packages on Github

: publish Maven packages on Maven Central

<dependencies>
    <dependency>
        <!-- core module required -->
        <groupId>net.seij.jakarta-ws-rs-hateoas</groupId>
        <artifactId>core</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <!-- if using jackson -->
        <groupId>net.seij.jakarta-ws-rs-hateoas</groupId>
        <artifactId>jackson</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

If using Jackson, configure Jackson to add module (Spring-way or JavaEE way)

ObjectMapper om = (new ObjectMapper())
om.addModule(JakartaWsRsHateoasModule.Instance)

Code Samples

  • see samples/sample-store-spring

Development installation

  • checkout project
  • ./mvnw clean install

Documentation in the Wiki for more details!

seij-jakarta-ws-rs-hateoas's People

Contributors

dependabot[bot] avatar sebastienjust avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.