Skip to content

A very simple ptoject/tutorial to show how to use Restlet and Gson libs under Android

Notifications You must be signed in to change notification settings

alchimya/android-restlet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

android-restlet

A very simple ptoject/tutorial to show how to use Restlet and Gson libs under Android

What is this?

It's a project tutorial that will help you to understand how to use Restlet framework (http:https://restlet.com/) and how to implement a JSON deserialization by using Gson Google framework (https://code.google.com/p/google-gson/).
You can use this project as template to develop your custom resource consumer.
With this class set you can consume at the same time resources from different uri service.
In this example we will consume in the same project resources from RestLet Demo service and from GitHub API service.

Packages

I developed this project wih Android Studio, however you can setup this code on your favourite IDE.
——>restlet.sdk
———> entities
———> http
—————> clients
—————> resources
———> interfaces
———> events
———> generics

  • restlet.sdk.entities

contains all classes to map JSON items of REST resources
  • restlet.sdk.http.clients

contains Restlet ClientResource singleton classes of REST resources
  • restlet.sdk.http.resources

contains helper classes that allow to consume REST resources with one or more operations for different REST path
  • restlet.sdk.interfaces

IClientResourceCallback: defines event method signatures for Restlet http callbacks
  • restlet.sdk.events

ClientResourceCallbackEventsManager: implements and dispatches Restlet http callbacks
  • restlet.sdk.generics

JsonToObject: is a generic T class tha allow to deserialize a JSON string into a custom class

How to use

To test this class set, I developed two REST service


Inside ContactResource class you will find a static method (getContact) that allow to consume the Contact.
See loadContact nethod inside MainActivity class.
Instead to consume GitRepos resource you have to refer to GitHubResource class and call ths static method getUserRepos.
See loadGitHubRepos nethod inside MainActivity class.

How to develop your custom resources

  • add your entities classes and map these classes with the corresponding JSON structure.

If the JSON response is an array you have to develop a class with a List attribute (see Contacts)
  • add your EntityClientResource.

For further details see ContactClientResource and GitHubClientResource classes.
However you create these classe by copying from ContactClientResource ord GitHubClientResource and by changing: baseUri value, _instance type and if you need to add custom settings you have to add them to getResource method.
  • add your EntityResource classes to define methods for REST operations

For further details see ContactResource and GitHubResource classes.

About

A very simple ptoject/tutorial to show how to use Restlet and Gson libs under Android

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages