ApiRegistory class

Register and manage ApiServer and Api.

For example

import 'dart:io';
import 'dart:convert';
import 'package:nimbus4flutter/nimbus4flutter.dart';

ApiRegistory.registApiServer(
  ApiServer(
    name: "local server",
    host: "localhost",
    requestBuilder: (request, method, input) {
      switch(method){
        case HttpMethod.POST:
        DataSet ds = input as DataSet;
        request.headers.contentType = new ContentType("application", "json", charset: "utf-8");
        request.write(
          JsonEncoder().convert(ds.toMap(toJsonType: true))
        );
        break;
      default:
        break;
      }
    },
    responseParser: (response, method, output) async{
      if(response.statusCode != 200){
        throw new Exception("error status = ${response.statusCode}");
      }
      if(output != null){
        DataSet ds = output as DataSet;
        ds.fromMap(JsonDecoder().convert(await response.transform(Utf8Decoder()).join()));
      }
    },
  )
);

ApiRegistory.registApi(
  SingleApi<DataSet,DataSet>(
    name: "get user",
    serverName: "local server",
    method:HttpMethod.POST
    path:"/users",
    inputCreator: (context){
      DataSet ds = DataSet("Condition");
      ds.setHeaderSchema(
        RecordSchema([FieldSchema<String>("name")])
      );
      return ds;
    },
    outputCreator: (context){
      DataSet ds = DataSet("User");
      ds.setHeaderSchema(
        RecordSchema(
          [
            FieldSchema<String>("name"),
            FieldSchema<int>("age"),
            FieldSchema<String>("tel"),
            FieldSchema<String>("address1"),
            FieldSchema<String>("address2")
          ]
        )
      );
      return ds;
    }
  )
);

Api api = ApiRegistory.getApi("get user");
RequestContext context = RequestContext();
DataSet request = api.getInput(context);
request.getHeader()["name"] = "hoge";
DataSet response = await api.request(request, context);

Constructors

ApiRegistory()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

apiRegistory Map<String, Api>
final
apiServerRegistory Map<String, ApiServer>
final

Static Methods

close({bool force = false}) → void
Close repository.
getApi<I, O>(String name) Api<I, O>?
Get Api with the specified name
getApiServer(String name) ApiServer?
Get ApiServer with the specified name
registApi(Api api) → dynamic
Register Api.
registApiServer(ApiServer server) → dynamic
Register ApiServer.