Library for HTTP requests with the common CRUD operations, pagination and error handling.

Features

  • Authentication with JWT.
  • HTTP error handling.
  • Helper for building REST routes.
  • Ready-to-use CRUD methods:
    • Get by ID (GET).
    • Paginated query (GET).
    • Paginated search (POST).
    • Add (POST).
    • Update (PUT).
    • Delete (DELETE).

Getting started

Initialize the IwsHttp library:

  IwsHttp.setup(
      authority: 'mydomain.com',
      apiKey: 'my_secret_api_key',
      basePath: 'api/',
      secureConnection: true,
      bearerToken: 'my_secret_token');

Usage

instantiate IwsHttpModel

final myModelProvider = IwsHttpModel<MyModelClass>(
    path: 'myModels',
    iwsHttp: IwsHttp(),
    fromJson: MyModelClass.fromJson,
    toJson: MyModelClass.toJson);

Make HTTP requests

int id = 120;
MyModelClass myModel = await myModelProvider.get(id);

await myModelProvider.update(myModel, id);

JSON structure for pagination

Paging queries expect a specific response format:

{
    "data": [],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 2,
        "per_page": 10,
        "to": 10,
        "total": 15
    } 
}

and the parameters for paging are sent in the request route as follows:

https://exmapledomain.com?page=1&orderBy=name&orderType=asc

Libraries

iws_http_model