ApiServerHttp class
It contains information about the server with the API and its processing.
For example
import 'dart:convert';
import 'package:http/http.dart';
import 'package:nimbus4flutter/nimbus4flutter.dart';
ApiServerHttp(
name: "local server",
host: "localhost",
requestBuilder: (request, method, input) {
switch(method){
case HttpMethod.POST:
DataSet ds = input as DataSet;
request.headers["Content-Type"] = "application/json;charset=utf-8";
(request as Request).body = 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 as StreamedResponse).stream.transform(Utf8Decoder()).join()));
}
},
);
Constructors
- ApiServerHttp({required String name, required String host, int? port, String scheme = "http", ApiServerHttpClientBuilder? builder, ApiServerUriBuilder? uriBuilder, ApiServerHttpRequestBuilder? requestBuilder, ApiServerHttpResponseParser? responseParser})
- Construct ApiServer
Properties
- client → HttpClient
-
HttpClient to communicate with the server.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → String
-
The hostname of the server.
no setterinherited
- name → String
-
A logical name of the server.
no setterinherited
- port → int?
-
The port of the server.
no setterinherited
- requestBuilder → ApiServerHttpRequestBuilder?
-
The process of building HttpClientRequest, an HTTP request to the server.
no setter
- responseParser → ApiServerHttpResponseParser?
-
the parsing process from HttpClientResponse, an HTTP response from the server, to the output DTO.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scheme → String
-
The scheme of the uri.
no setterinherited
- uriBuilder → ApiServerUriBuilder?
-
The process of building path, an HTTP request to the server.
no setterinherited
Methods
-
close(
{bool force = false}) → void -
Close server.
override
-
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