Skip to content

Latest commit

 

History

History
102 lines (71 loc) · 3.44 KB

guide.rst

File metadata and controls

102 lines (71 loc) · 3.44 KB

Quickstart

First, add the dependency to your project.

Maven

<dependency>
    <groupId>de.whitefrog</groupId>
    <artifactId>frogr-base</artifactId>
    <version>0.2.2</version>
</dependency>

Application

Next we will create the main entry point for the service.

../../examples/basic/src/main/java/de/whitefrog/frogr/example/basic/MyApplication.java

As you can see there are two registry calls in the application's constructor. register(...) let's the application know in which package to look for rest classes. serviceInjector().service().register(...) tells the application where to look for models and repositories. More information about the Application entry point: Application <documentation/application>

Configs

You may also have noticed there's a config file used in the main method. This is required to setup our Dropwizard instance, so we have to create that one now. There's a second config file needed, which configures our embedded Neo4j instance. By default these configs should be in your project in a directory 'config'.

config/example.yml

../../examples/config/example.yml

Reference: Dropwizard Configuration

config/neo4j.properties

../../examples/config/neo4j.properties

This file is not required, by default the graph.location is "graph.db" inside your working directory. Reference: Neo4j Configuration

RelationshipTypes

We should add a class that holds our relationship types, so that we have consistent and convienient access. This is not a requirement but I highly recommend it. Doing so we don't have to deal with strings in Java code, which is never a good choice, right?

../../examples/basic/src/main/java/de/whitefrog/frogr/example/basic/RelationshipTypes.kt

Model

Now, let's create a model <documentation/models>. I recommend using Kotlin for that. All models have to extend the Entity class or implement the Model interface at least.

../../examples/basic/src/main/java/de/whitefrog/frogr/example/basic/model/Person.kt

As you can see, we used the relationship types created before, to declare our relationships to other models.

Repository

Normally we would create a repository for persons. But we won't need extra methods for this tutorial and frogr will create a default repository if it can't find one. If you need more information visit documentation/repositories.

Service

Next we'll have to create the REST service <documentation/services> layer. There's a base class, that provides basic CRUD operations, so you only have to add methods for special cases. Of course you can also use any other JAX-RS annotated class.

../../examples/basic/src/main/java/de/whitefrog/frogr/example/basic/rest/Persons.java

Examples

You can find the code used in this guide and more examples at Github