Technology Stack

  • Choose between Spring MVC or Spring Boot
  • Support a 3rd level RESTful API out of the box with HATEOAS
  • Allow clients to use plain model-based REST or JSON API 1.x
  • Enjoy effortless, model-driven search endpoints with sorting, paging and dynamic criteria support for simple URL params or RSQL/FIQL
  • Use a 3-tier architecture without the boilerplate with restdude-mdd
  • Annotate your models to configure API documentation, authorization, validation and auditing
  • Sleep better with built-in error-management
  • Customize and integrate according to your needs with Spring Security
  • Interact with your users via websockets and STOMP
  • Persist to relational databases with JPA
  • Free your persisted data structures with ElasticSearch, Solr, MongoDB, Redis, Cassandra, Counchbase, Neo4J, Hazelcast and more
  • Automate basic or fine grained auditing using Envers and Javers
  • Publish REST API documentation effortlesly thanks to Springfox and Swagger UI
  • Optional web UI and admin panel provided out-of the-box based on bootstrap 4, backbone.marionette, core-UI, requirejs and more.
  • Coming up:
    • Support for json-ld and hydra via model annotations.
    • Dynamic CORS headers with fine-grained config down to entity model records
  • Support for JWT (JSON Web Token)

Why?

Contrary to other frameworks that squeeze everything within two (i.e. Controller, Repository) or even a single tier, restdude provides effortless SCRUD services by generating controller, service and repository components for you classes during application startup.

This provides an extensible 3-tier architecture without any need for boilerplate code and allows to replace and extend the generated components with your own at any time when custom or otherwise additional functionality is needed.

Besides automating SCRUD, restdude provides other conveniences with a focus on hypermedia, like dynamic generation of HATEOAS/JSON-API links and controller request mappings based on entity model relationships.

Model Driven

Usecases in Restdude are typically modeled while broken down to four major tiers:

  • Entity, transfer, or other models
  • Controllers providing the relevant RESTful HTTP mappings
  • Services providing business logic and integration methods
  • Repositories for data operations like persistance, indexing, messaging etc.

Model-based RESTful services for SCRUD, uploads, metadata, JSONSchema etc. are generated automatically. Models are just POJOs and can be JPA entities, ElasticSearch documents etc. Any Spring Data module can be easily plugged-in to support other NoSQL datastores.

Models also include annotations and other metadata used to declaratively compose usecase implementation details like HTTP mappings, authorization rules, tier components, validation rules, model-to-model-mappings, applications events handlers etc.

Ten Second Example

Consider the following sample model

    @Entity
@Table(name = "host")
@ModelResource(
path = "hosts",
apiName = "Hosts",
apiDescription = "Operations about hosts")
public class Host extends AbstractSystemUuidPersistable {

@NotNull
@Column(name = "name", nullable = false, unique = true)
private String name;

@NotNull
@Column(name = "description", length = 500, nullable = false)
private String description;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "country_id", referencedColumnName = "id")
private Country country;

@OneToMany(mappedBy = "host")
private List<Site> sites;


// other properties, getters/setters etc.
}

Generated Components

Based on the above model, restdude will generate any missing components like a `Controller`, `Service` and `Repository` to give you the following architecture without the need for boilerplate code. You can replace or extend those with your custom components at any time.

                    +-------------------------+   +---------------------+   +------------------+
 Browser, App,      | RESTful SCRUD           |   | Content negotiation |   | Websockets       |
 or other Client    +-------------+-----------+   +-----------+---------+   +-------+----------+
                                  |                           |                     |
--------------------------------- | ------------------------- | ------------------- | -----------
                                  |                           |                     |
                      JSON+HATEOAS or JSON-API 1.x            |                     |
 Network              with RSQL/FIQL or URL params            |                   STOMP
                                  |                           |                     |
                                  |                           |                     |
--------------------------------- | ------------------------- | ------------------- | -----------
                                  |                           |                     |
                    +-------------+---------------------------+----------+  +-------+----------+
                    | HostController                                     +--+ Message Broker   |
                    +--------------------------+-------------------------+  +-------+----------+
                                               |                                    |
 Restdude                                      |                                    |
                    +--------------------------+------------------------------------+----------+
                    |                                HostService                               |
                    +--------+--------------------+---------------------+---------------+------+
                             |                    |                     |               |
                             |                    |                     |               |
                    +--------+-------+ +----------+-----------+ +-------+-------+ +-----+------+
                    | HostRepository | | FileService (FS, S3) | | EmailService  | | Misc Util  |
                    +----------------+ +----------------------+ +---------------+ +------------+

Generated Services

Some of the RESTful services provided out of the box for the above model:

Method Path Description
GET /api/rest/hosts/{id} Fetch the host matching the id
GET /api/rest/hosts/{id}/relationships/country Fetch the country of the host matching the id
GET /api/rest/hosts/{id}/relationships/sites Search the sites of the host matching the id, see search endpoints bellow for filtering and other options (paged)
GET /api/rest/hosts?country.code=GR&name=%25startsWith Search based on model properties (paged)
GET /api/rest/hosts?filter=country.code=in=(GR,UK);name==%25startsWith Search based on model properties using RSQL or FIQL (paged)
POST /api/rest/hosts Create a new host
PUT /api/rest/hosts/{id} Update the host matching the id
PATCH /api/rest/hosts/{id} Partially update the host matching the id
DELETE /api/rest/hosts/{id} Delete the host matching the id
GET /api/rest/hosts/jsonschema Get the JSONSchema for hosts

The endpoints support the following content types:

  • application/json and application/hal+json for HATEOAS Resource response and plain JSON request bodies, with both being based on model structure
  • application/vnd.api+json for JSON-API-compliant request/response bodies

Overview

Working with Models

Entity Models

Graph Models

Generated Components

Contrary to other frameworks like spring-data-rest and jhipster, restdude provides effortless SCRUD services by generating controller, service and repository classes during application startup.

This provides an extensible 3-tier architecture without any need for boilerplate code and allows to replace and extend the generated components with your own at any time when custom or otherwise additional functionality is needed. Restdude will simply not generate components that overlap with those already available.

A modern SPA wbapp that automatically adopts to the above and can be manageably customized and extended further is also provided.

Validation.

Bean validation is supported.

Custom Components

Backend is based on Spring 4.x. Support classes include controllers, converters, (de)serializers, services, repositories, base models and much more.

Controllers

Services

Repositories

JPA repositories work with practically any relational database and support entity graphs. Popular NoSQL data stores can be easily setup thanks to spring-data modules.

I18n

Standard Java message property resources are used in the backend by default. Those are placed in the classpath root and include properties for build-in functionality like registration, confirmation and password-reset emails. JSON labels are used on the client-side by default and similarly include standard Web UI messages for build-in models etc. Client i18n is based on requirejs.

Authentication and Authorization

Very flexible, based on Spring Security. Integrates with practically anything.

Social Networks Integration

Social network support includes transparent registration and sign-in via any major social network. Spring social provides an API for implementing other integrations.

Auditing

Basic entity-based auditing is supported via using Spring Data/Hibernate Envers annotations or interfaces in your models. Complex auditing is supported via Javers

Error Management

All exceptions occurring as a result of REST processing will generate a SystemError instance, persist it and serialize as the JSON HTTP response. Stacktrace hashes, excluding line numbers, are used to group and efficiently manage and store records. Client applications can utilize the same infrastructure to persist ClientErrors.

Errors can be managed via the REST API or through the web UI.

Indexing

Indexing uses ElasticSearch by default.

Email

Web Sockets

Controller message mappings provide access to request-response access and topic subscriptions via the “app” and “topic” destination prefixes respectively. Any service can easily message topics and collection or individual user queues. Websocket sessions and subscriptions are handled via application events

Browser Client

Frontend is based on backbone.marionette and similarly provides base models, model-driven UI components views and layouts (forms, menus etc.), converters, formatters, routes and more.

Dynamic Components

Customization

I18n

Swagger API Reference

The webapp provides automatically-generated API documentation based on Swagger and created by Springfox. To access the documentation run the app and point your browser to http://localhost:8080/restdude/apidoc.

Responsive image

License

Restdude Hub DVD Rental is distributed under the GNU Affero General Public License