Opinionated APIs for web & mobile applications.
Read this in other languages: 中文.
Elide is a Java library that lets you set up a GraphQL or JSON API web service with minimal effort starting from a JPA annotated data model.
Elide supports a number of features:
Control access to fields and entities through a declarative, intuitive permission syntax.
JSON-API & GraphQL lets developers fetch entire object graphs in a single round trip. Only requested elements of the data model are returned. Our opinionated approach for mutations addresses common application scenarios:
- Create a new object and add it to an existing collection in the same operation.
- Create a set of related, composite objects (a subgraph) and connect it to an existing, persisted graph.
- Differentiate between deleting an object vs disassociating an object from a relationship (but not deleting it).
- Change the composition of a relationship to something different.
- Reference a newly created object inside other mutation operations.
Filtering, sorting, pagination, and text search are supported out of the box.
Elide supports multiple data model mutations in a single request in either JSON-API or GraphQL. Create objects, add them to relationships, modify or delete together in a single atomic request.
Elide is agnostic to your particular persistence strategy. Use an ORM or provide your own implementation of a data store.
Explore, understand, and compose queries against your Elide API through generated Swagger documentation or GraphQL schema.
Customize the behavior of data model operations with computed attributes, data validation annotations, and request lifecycle hooks.
More information about Elide can be found at elide.io.
To try out an Elide example service (with a Postgres database), you can deploy via Heroku.
The code that generates this example can be found here
Alternatively, use elide-standalone which allows you to quickly setup a local instance of Elide running inside an embedded Jetty application.
To use Elide, create a set of JPA annotated data models that represent the domain model of your web service:
@Entity
public class Book {
@Id
private Integer id;
private String title;
@ManyToMany(mappedBy = "books")
private Set<Author> authors;
}
Add Elide annotations to both expose your models through the web service and define security policies for access:
@Entity
@Include(rootLevel = true)
@ReadPermission("Everyone")
@CreatePermission("Admin OR Publisher")
@DeletePermission("Noone"
@UpdatePermission("Noone")
public class Book {
@Id
private Integer id;
@UpdatePermission("Admin OR Publisher")
private String title;
@ManyToMany(mappedBy = "books")
private Set<Author> authors;
}
Add Lifecycle hooks to your models to embed custom business logic that execute inline with CRUD operations through the web service:
@Entity
@Include(rootLevel = true)
@ReadPermission("Everyone")
@CreatePermission("Admin OR Publisher")
@DeletePermission("Noone")
@UpdatePermission("Noone")
public class Book {
@Id
private Integer id;
@UpdatePermission("Admin OR Publisher")
private String title;
@ManyToMany(mappedBy = "books")
private Set<Author> authors;
@OnCreatePreCommit
public void onCreate(RequestScope scope) {
//Do something
}
}
Map expressions to security functions or predicates that get pushed to the persistence layer:
@SecurityCheck("Admin")
public static class IsAdminUser extends UserCheck {
@Override
public boolean ok(User user) {
return isUserInRole(user, UserRole.admin);
}
}
To query and expose these models, follow the steps documented in the getting started guide.
For example API calls, look at:
Security is documented in depth here.
Please refer to the contributing.md file for information about how to get involved. We welcome issues, questions, and pull requests.
If you are contributing to Elide using an IDE, such as IntelliJ, make sure to install the Lombok plugin.
Discussion is on spectrum or through filing issues.
This project is licensed under the terms of the Apache 2.0 open source license. Please refer to LICENSE for the full terms.
Create a JSON API REST Service With Spring Boot and Elide
Custom Security With a Spring Boot/Elide Json API Server
Logging Into a Spring Boot/Elide JSON API Server
Securing a JSON API REST Service With Spring Boot and Elide
Creating Entities in a Spring Boot/Elide JSON API Server
Updating and Deleting with a Spring Boot/Elide JSON API Server