Skip to content

VladSumtsov/santarest

 
 

Repository files navigation

SantaRest

Durable library for easily HTTP requests executing with the help of EventBus for Android and Java.

What's this for?

SantaRest makes profit in such ways:

  1. Flexibility and easy using (Thanks Retrofit)
  2. Decoupling networking code from application and receiving responses in different places with EventBus (Thanks Otto and EventBus) With the help of SantaRest you can create application with network communication but without callbacks and Android activity's life-cycle checking.

Usage

To send and receive HTTP requests you should use SantaRest class

santaRest = new SantaRest.Builder()
                .setServerUrl("https://api.github.com")
                .build();

Each HTTP request in SantaRest is an individual class which contains all information about the request and response. We call it as Action.

For creating an Action you should write a class with annotation @RestAction. Example:

@RestAction(value = "/demo",
        method = RestAction.Method.GET)
public class ExampleAction {

}

In the Action class you can describe information about request using fields with annotations:

  • @Path for path value
  • @Query for request URL's parameters
  • @Body for POST requests's body
  • @RequestHeader for request headers
  • @Field for request's fields if request type is RestAction.Type.FORM_URL_ENCODED
  • @Part for multipart request's parts

To receive information of response you can use special annotations:

  • @Response for getting response body.
  • @Status for getting response status. You can use Integer or Long fields for get status code or use boolean if you want to know request is sent successfully
  • @ResponseHeader for getting response headers

To send an action you should use method sendAction. After this request will be created, parsed and filled by response. To receive filled actions you should use:

santaRest.subscribe(this);

But don’t forget to unsubscribe from it:

santaRest.unsubscribe(this);

For android we recommend you to use santaRest.subscribe() at onResume and santaRest.unsubscribe(this) at onPause methods.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%