Introduction
retrofit-request is a Retrofit clone. Its a wrapper of request
using TypeScript's decorator feature for making cleaner HTTP request.
@ @ public static async return null; try //making a GET request to http://some.api.com/get/something?id=123 let result = await MyAPI; catche{}
API Declaration
Annotations on the class methods and its parameters indicate how a request will be handled.
REQUEST METHOD
Every method must have an HTTP annotation that provides the request method and relative URL. There are two built-in annotations: GET, POST. The relative URL of the resource is specified in the annotation.
@
You can also specify query parameters in the URL.
@
URL MANIPULATION
A request URL can be updated dynamically using replacement blocks and parameters on the method. A replacement block is an alphanumeric string surrounded by { and }. A corresponding parameter must be annotated with @Path using the same string.
@public async : Promise<any> return null;
Query parameters can also be added.
@public async : Promise<any>return null;
REQUEST BODY
An object can be specified for use as an HTTP request body with the @Body annotation.
@public async ;
The objects` method will be discarded
FORM ENCODED AND MULTIPART
Methods can also be declared to send form-encoded and multipart data.
Form-encoded data is sent when @FormUrlEncoded is present on the method. Each key-value pair is annotated with @Field containing the name and the object providing the value.
@@FormUrlEncodedpublic async : Promise<User>return null;
Multipart requests are used when @Multipart is present on the method. Parts are declared using the @Part annotation.
@@Multipartpublic async : Promise<User>return null;
HEADER MANIPULATION
A request Header can be updated dynamically using the @Header annotation. A corresponding parameter must be provided to the @Header. If the value is null, the header will be omitted.
@public async : Promise<User> return null;
An evaluator can be specified with @Header as well as other parameter annotations, when evaluator is given the parameter will be applied to the evaluator
@public async : Promise<User> return null;
The header would be {"Authorization": "auth_header_123_spetial"}