crnk example application
WARNING: this example project is still in development and subject to various improvements, see roadmap
Crnk requires Java 8 or later.
Crnk is licensed under the Apache License, Version 2.0. You can grab a copy of the license at http://www.apache.org/licenses/LICENSE-2.0.
Building from Source
Crnk make use of Gradle for its build. To build the project run
Running the application
In order to run this example do:
docker run --name=crnk -p 8080:8080 crnk/example
The JSON API endpoint will be available at:
Some further URLs to play around that show the power of Crnk:
http://127.0.0.1:8080/api/movie http://127.0.0.1:8080/api/movie/44cda6d4-1118-3600-9cab-da760bfd678c http://127.0.0.1:8080/api/movie/44cda6d4-1118-3600-9cab-da760bfd678c http://127.0.0.1:8080/api/movie/44cda6d4-1118-3600-9cab-da760bfd678c/project http://127.0.0.1:8080/api/movie/44cda6d4-1118-3600-9cab-da760bfd678c/relationships/project http://127.0.0.1:8080/api/movie?sort=-name http://127.0.0.1:8080/api/movie?sort=-id,name http://127.0.0.1:8080/api/movie?sort=id&page[offset]=0&page[limit]=2 http://127.0.0.1:8080/api/movie?filter[name]=Iron Man http://127.0.0.1:8080/api/movie?filter[name][EQ]=Iron Man http://127.0.0.1:8080/api/movie?filter[name][LIKE]=Iron http://127.0.0.1:8080/api/schedule http://127.0.0.1:8080/api/meta/resource http://127.0.0.1:8080/api/vote?fields=name // demos fields set & performance issues http://127.0.0.1:8080/api/secrets // demos error http://127.0.0.1:8080/api/facet?filter[resourceType]=movie // get movie facets
Make sure to enable annotation processing support when using IntelliJ IDEA. Otherwise it will not be able to find the generated sources from the Crnk annotation processor (type-safe Query objects).
The project makes use of https://github.com/rmee/gradle-plugins/ for the build setup.
- if no JAVA_HOME is configured (recommended), a suitable JDK will be downloaded automatically
src/main/helmholds a Helm chart to deploy to Kubernetes.
- Deployment to Kubernetes is triggered by the
deploytask. All the deployment is confined to Docker images and a project-specific home directory located in
build/home. No installation of any tooling necessary thanks to the plugins in use. Further wrapper scripts like
./kubectlallow to use this deployment setup from a shell (GitBash, Linux, etc.). For deployment
CRNK_GCLOUD_CLUSTERenvironment variables must be set and credentials be available in
crnk-example-service project showcases:
- Use of Lombok to avoid getter/setter boiler-plate.
- Integration of Crnk into Spring Boot
io.crnk:crnk-format-plain-jsonhas been applied for slightly simplified version of JSON:API without
- A simple in-memory repository with
ScreeningRepositorythat keeps all resources in a map.
- Exposing entities with crnk-jpa using
PersonRepository, etc. extending
JpaEntityRepositoryBase. Behind the scenes the
QuerySpecis translated to an efficient JPA Criteria query.
- A manually written repository with
VoteRepository. It makes use of Thread.sleep to simulate heavy work.
- A custom exception is introduced with
CustomExceptionMapperthat is mapped to a JSON API error and HTTP status code.
ScreeningRepositoryto handle use cases where the related ID is easy to get, which in turn allows to omit having to implement relationship repositories.
- implementing a relationship repository with
- implementing a multi-valued nested resource with
Secretand its identifier
- implementing a single-valued nested resource with
SecreeningStatus. Shared the same ID as the screening itself and make use of
SerializeType.EAGERto directly be shown with the screening (see http://127.0.0.1:8080/api/screening)
- introducing new relationships to existing resources
without touching those resources with
PersonEntityas dynamic resource by annotating a
Map-based field with
SecurityConfigurationperforms a OAuth setup with GitHub as provider.
LoginRepositorygives access to information about the logged-in user through http://localhost:8080/api/user. Enable spring security in the
application.yamlto make use of the security features. Security is disabled by default to facilitate playing with the example app. The security setup is still work in progress.
XSRFin Angular terminology) protection through
ExampleSecurityConfigurerto setup role-based access control.
ScheduleDecoratorFactoryto intercept and modify requests to repositories.
- The documentation gets generated to
gradlew build. Have a look at the
build.gradlefile and the capturing based on
AsciidocCaptureModulewithin the test cases.
- Support for facetted search by applying
MovieEntity.yearas been marked as being facetted with
MovieRepositoryprovides an interface for the
MovieRepositoryImplwhich allows type-safe access to movie result lists in
MovieRepositorymakes use of
HasMoreResourcesMetaInformationthrough a custom
MovieListtype. This triggers the use of a previous/next paging strategy, rather than always computing the total count in a second, potentially expensive query.
TestDataLoader will automatically setup some test data upon start.
The project itself makes use of an number of third-party plugins to bootstrap a JDK, build Helm packages and allow a Kubernetes installation to Google Cloud. For more information see https://github.com/rmee/gradle-plugins/.
Feedback and PRs very welcomed!