Skip to content

TypedRest/TypedRest-Java

Repository files navigation

TypedRest for Java/Kotlin

Build API documentation
TypedRest for Java/Kotlin helps you build type-safe, fluent-style REST API clients. Common REST patterns such as collections are represented as classes, allowing you to write more idiomatic code.

Java

MyClient client = new MyClient(URI.create("http://example.com/"));

// GET /contacts
List<Contact> contactList = client.getContacts().readAll();

// POST /contacts -> Location: /contacts/1337
ContactEndpoint smith = client.getContacts().create(new Contact("Smith"));
//ContactEndpoint smith = client.getContacts().get("1337");

// GET /contacts/1337
Contact contact = smith.read();

// PUT /contacts/1337/note
smith.getNote().set(new Note("some note"));

// GET /contacts/1337/note
Note note = smith.getNote().read();

// DELETE /contacts/1337
smith.delete();

Kotlin

val client = MyClient(URI("http://example.com/"))

// GET /contacts
val contactList: List<Contact> = client.contacts.readAll()

// POST /contacts -> Location: /contacts/1337
val smith: ContactEndpoint = client.contacts.create(Contact("Smith"))
//val smith: ContactEndpoint = client.contacts["1337"]

// GET /contacts/1337
val contact: Contact = smith.read()

// PUT /contacts/1337/note
smith.note.set(Note("some note"))

// GET /contacts/1337/note
val note: Note = smith.note.read()

// DELETE /contacts/1337
smith.delete()

Read an Introduction to TypedRest or jump right in with the setup guide.

You can also take a look at our Sample project.

Maven artifacts

Artifact group: net.typedrest

typedrest
The main TypedRest library.

typedrest-serializers-jackson
Adds support for serializing using Jackson instead of kotlinx.serialization.
Pass new JacksonJsonSerializer() to the EntryEndpoint constructor.

typedrest-serializers-moshi
Adds support for serializing using Moshi instead of kotlinx.serialization.
Pass new MoshiJsonSerializer() to the EntryEndpoint constructor.

About

Build type-safe fluent-style JSON REST API clients in Java or Kotlin

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages