Description
Voyager Server is a set of very extensible Spring Boot helper classes and interfaces that help creating REST endpoints for models, including easy Access Control Level (ACL) and before/after create/read/update/delete hooks.
voyager-server-spring-boot-starter alternatives and similar libraries
Based on the "Web" category.
Alternatively, view voyager-server-spring-boot-starter alternatives based on common mentions on social networks and blogs.
-
ktor
Framework for quickly creating connected applications in Kotlin with minimal effort -
javalin
A simple and modern Java and Kotlin web framework [Moved to: https://github.com/javalin/javalin] -
apollo-android
:robot: A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform. -
http4k
The Functional toolkit for Kotlin HTTP applications. http4k provides a simple and uniform way to serve, consume, and test HTTP services. -
GraphQL Kotlin
Libraries for running GraphQL in Kotlin -
jooby
The modular web framework for Java and Kotlin -
KVision
Object oriented web framework for Kotlin/JS -
spark-kotlin
A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha -
skrape.it
A Kotlin-based testing/scraping/parsing library providing the ability to analyze and extract data from HTML (server & client-side rendered). It places particular emphasis on ease of use and a high level of readability by providing an intuitive DSL. It aims to be a testing lib, but can also be used to scrape websites in a convenient fashion. -
hexagon
Hexagon is a microservices toolkit written in Kotlin. Its purpose is to ease the building of services (Web applications or APIs) that run inside a cloud platform. -
firefly
Firefly is an asynchronous web framework for rapid development of high-performance web application. -
KGraphQL
A GraphQL implementation written in Kotlin -
fritz2
Easily build reactive web-apps in Kotlin based on flows and coroutines. -
A pure Kotlin, UI framework
A pure Kotlin UI framework for the Web (and desktop). -
Kanary
A minimalist web framework for building REST APIs in Kotlin/Java. -
vaadin-on-kotlin
Writing full-stack statically-typed web apps on JVM at its simplest -
alpas
🚀 The Rapid and Delightful Kotlin Web Framework. Easy, elegant, and productive! -
kraph
GraphQL request string builder written in Kotlin -
krawler
A web crawling framework written in Kotlin -
ShapeShift️
A Kotlin/Java library for intelligent object mapping and conversion between objects. -
yested
A Kotlin framework for building web applications in Javascript. -
KotlinPrimavera
Spring support libraries for Kotlin -
lambda-kotlin-request-router
A REST request routing layer for AWS lambda handlers written in Kotlin -
kog
🌶 A simple Kotlin web framework inspired by Clojure's Ring. -
tekniq
A framework designed around Kotlin providing Restful HTTP Client, JDBC DSL, Loading Cache, Configurations, Validations, and more -
sponge
sponge is a website crawler and links downloader command-line tool -
Pellet
An opinionated, Kotlin-first web framework that helps you write fast, concise, and correct backend services 🚀. -
bootique-kotlin
Provides extension functions and features for smooth development with Bootique and Kotlin. -
Zeko-RestApi
Asynchronous web framework for Kotlin. Create REST APIs in Kotlin easily with automatic Swagger/OpenAPI doc generation -
graphql-kotlin-toolkit
GraphQL toolkit for Kotlin. -
komock
KoMock - Simple HTTP/Consul/SpringConfig http server framework written in Kotlin. Wiremock use cases -
kweb-core
Build rich live-updating web apps in pure server-side Kotlin. -
graphql-kotlin
Code-only GraphQL schema generation for Kotlin
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of voyager-server-spring-boot-starter or a related project?
README
voyager-server-spring-boot-starter
What is Voyager Server?
Voyager Server is a set of helper classes and interfaces that help creating REST endpoints for models, including easy Access Control Level (ACL) and before/after create/read/update/delete hooks (see ACLs and Hooks for details).
The following endpoints are generated:
- POST /
- Receives the entity to be created in the body
- GET /
- Supports sort_by query parameter with the following format
sort_by=<field>:<asc/desc>
(for example,sort_by=createdAt:desc
) - Supports pagination by query parameters:
- page_no
- If not present, will default to 0
- page_size
- If not present, will default to 20
- Supports filtering by specifying the fields to filter by as query parameters in the format
<field>=<value>
or<field>=<operation>:<operation term>
, for example: - name=John
- name=eq:"John"
- Note that when the operation is explicit, strings must be warped in double quotes
- name=neq:"John"
- name=in:"John","Bob"
- Multiple values can be delimited by comma, if the operation is of such nature that it accepts an array of terms
- age=gte:10
- If no double quotes are used (such as in this case) the value will be parsed to a number
- gender=eq:null
- In no double quotes are used (such as in this case), and the value is "null", then it will be parsed as
null
- In no double quotes are used (such as in this case), and the value is "null", then it will be parsed as
- Supports sort_by query parameter with the following format
- GET /{id}
- PUT /{id}
- Receives the full (not just the changed fields) updated entity in the body
- The id of an entity will not be changed, event if send in the body
- DELETE /{id}
Add to your project
Gradle
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.alexnix:voyager-server-spring-boot-starter:<VERSION>'
}
<VERSION> may be a commit hash, for example 63d7ee5
Maven
Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.alexnix</groupId>
<artifactId>voyager-server-spring-boot-starter</artifactId>
<version>VERSION</version>
</dependency>
<VERSION> may be a commit hash, for example 63d7ee5
How to use
Step 1. Create a model that extends HasId
Kotlin
@Entity
@Table(name="books")
data class Book(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
override var id: Long = 0,
val title:String,
val author:String
): HasId
Java
@Entity
@Table(name = "books")
public class Book implements HasId {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public String title;
public String author;
@Override
public long getId() {
return id;
}
@Override
public void setId(long id) {
this.id = id;
}
... the rest of the getters and setters ...
}
Step 2. Create a repository that extends a VoyagerRepository (for example VoyagerRepositoryJPA)
Kotlin
interface BookRepo: VoyagerRepositoryJPA<Book>
Java
public interface BookRepo extends VoyagerRepositoryJPA<Book> {
}
Step 3. Create a service that extends a VoyagerService (for example VoyagerServiceJPA)
Kotlin
@Service
class BookService(private val repo: BookRepo): VoyagerServiceJPA<Book>(repo)
Java
@Service
public class BookService extends VoyagerServiceJPA<Book> {
public BookService(@NotNull VoyagerRepositoryJPA<Book> repo) {
super(repo);
}
}
Step 4. Create a controller that extends VoyagerController
Kotlin
@RestController
@RequestMapping("/books")
class BookCtrl(r: BookService): VoyagerController<Book, BookService>(r)
Java
@RestController
@RequestMapping("/books")
public class BookCtrl extends VoyagerController<Book, BookService> {
public BookCtrl(@NotNull BookService service) {
super(service, new DefaultACL<>(), new DefaultHooks<>());
}
}
ACLs
ACL is a way to enforce access permission for the create/read/update/delete operations. To do so, there are two options:
- provide a custom ACL object (extends ACL) in the controller constructor, or
- override the corresponding functions in the controller
The following code snippet prohibits any delete operations:
Kotlin
override fun deleteAcl(item: Book) = false
Java
@Override
public boolean deleteAcl(@NotNull Book item) {
return false;
}
Complex permission logic can be implemented inside those methods, by looking at the current user object (obtained from spring-security) and at the object being changed. For example to restrict deleting of objects, just the their owner of the an administrator. Such logic would look like:
override fun deleteAcl(item: Book) = currentUser.roles.includes("admin") || currentUser.id == book.owner_id
Hooks
Hooks provide a way to react to events before and after they happen. Note, that hooks cannot enforce permissions (ACLs should be used for this) but the beforeReadMany
hook provides a way to mutate the query filters, so this can, for example, restrict a uses from reading all entities, with the exception of his own, by programmatically adding a filter such as: owner_id=eq:<current_used.id>
.
Same as ACLs, hooks can be implemented in two different options:
- provide a custom Hooks object (extends Hooks) in the controller constructor, or
- override the corresponding functions in the controller
Additionally, whatever the after
hooks return will be returned in the HTTP response. So this functionality can be used to send responses that deviate from the classic REST responses.
Such responses are marked with the __voyager_api
JSON key and must follow the following schema:
{
__voyager_api: true,
post?: Object[],
put?: Object[],
delete?: Object[],
}
This is useful for informing the client of side effects, in response to an event, for example creating a restaurant review will create (post) the review object and will update (put) the restaurant object, by adjusting its rating. In this scenario, the VoyagerResponse object will have the appropriate values in the post
and put
fields.
The following table describes typical use cases for each hook. Where empty, there was not a clear use case for them, but where added for symmetry.
Create | Read Many | Read One | Update | Delete | |
---|---|---|---|---|---|
Before | Add server generated fields, such as owner id or createdAt | Add filters (query where clauses), for example to restrict the query only to entities where owner_id == user_id | |||
After | Create/update/delete side effect entities and return them in a VoyagerResponse object | Populate foreign keys fields with the actual objects | Create/update/delete side effect entities and return them in a VoyagerResponse object | Create/update/delete side effect entities and return them in a VoyagerResponse object |
Demo Projects
- Java
- Kotlin [coming soon]