Models

Endpoint Models represent the schema of your API resources. Lets take look at some important points of our Person endpoint example:

@Endpoint(path = "/people")
public class Person {

    @Id
    IdRef<Person> id;

    @Index
    String name;

}

@Endpoint

The beginning of everything is the @Endpoint annotation. It defines a new endpoint and the base route of its APIs to be /people.

Primitive Properties

The primitive types that can be used as models attributes are describe in the following table. More complex types can be persisted using the @Json annotation:

Type Java type(s)
Integer short, int, long, java.lang.Short, java.lang.Integer, java.lang.Long
Floating-point number float, double, java.lang.Float, java.lang.Double
Boolean boolean, java.lang.Boolean
Text String
Date java.util.Date

@Id

All models should have one, and only one, IdRef attribute annotaded with @Id. This is the id of your model and it will be used to access its information or to create a relationship with another model.

@Index

The @Index annotation tells yawp to create indexes to allow queries using this attribute as a filter or order clause.

@Json

If you want store a more complex object inside your model, you will need to serialize the attribute as a json string. For instance:

@Json
Address address;

@Text

It is used to mark a string attribute as a large text value. When you use this annotation you can store larger texts but you can’t create indexes over this attribute anymore.

@Text
String comment;

@ParentId

It is possible to create entity groups based on ancestor keys. In Appengine Datastore this is used to obtain strong consistency queries where it is necessary. To do so, you add an IdRef to the ancestor model of your model, annotate it with @ParentId:

@ParentId
IdRef<Company> companyId;