APIServer class

An API HTTP Server

Inheritance

Constructors

APIServer(APIRoot apiRoot, String address, int port, {String? name = 'Bones_API', String? version = BonesAPI.VERSION, int? securePort, bool letsEncrypt = false, bool? letsEncryptProduction, bool? allowRequestLetsEncryptCertificate, Object? letsEncryptDirectory, bool hotReload = false, Object? documentRoot, Object? domains, bool cookieless = false, bool? useSessionID, int? totalWorkers = 1, String? apiCacheControl, String? staticFilesCacheControl, bool? cacheStaticFilesResponses, Duration? serverResponseDelay, bool? logToConsole, bool? logQueue})
APIServer.fromArgs(APIRoot apiRoot, List<String> args)
APIServer.fromConfig(APIRoot apiRoot, APIServerConfig serverConfig)

Properties

address String
The bind address of this server.
finalinherited
allowRequestLetsEncryptCertificate bool
If true allows the request of Let's Encrypt certificates.
finalinherited
apiCacheControl String
The cache-control header for API responses.
finalinherited
apiConfig APIConfig?
The APIConfig of the APIRoot.
finalinherited
apiInfoURL String
The local API-INFO URL of this server.
no setterinherited
apiRoot APIRoot
The API root of this server.
finalinherited
args → ArgsSimple
All the parsed arguments, using ArgsSimple.
finalinherited
cacheStaticFilesResponses bool
If true will cache static files. Default: true
finalinherited
canUseLetsEncrypt bool
Returns true if the basic conditions for Let's Encrypt are configured.
no setterinherited
cookieless bool
If true will remove any Set-Cookie or Cookie header.
finalinherited
development bool
finalinherited
domains List<String>
Returns a list of domains at domainsRoots keys (non RegExp entries).
no setterinherited
domainsRoots Map<Pattern, Directory>
The domains root directories.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
hotReload bool
If true enables Hot Reload (APIHotReload.enable).
finalinherited
id int
ID of this instance.
latefinalinherited
isStarted bool
Returns true if this servers is started.
no setterinherited
isStarting bool
Returns true if this instance is currently in the process of starting.
no setterinherited
isStopped bool
Returns true if this server is closed.type
no setterinherited
letsEncrypt bool
If true enabled Let's Encrypt.
finalinherited
letsEncryptDirectory Directory?
The Let's Encrypt certificates Directory.
finalinherited
letsEncryptProduction bool
If true runs Let's Encrypt in production mode.
finalinherited
logQueue bool
If false disables log flush queue.
latefinalinherited
logToConsole bool
If true log messages to stdout (console).
latefinalinherited
name String
The name of this server.
finalinherited
port int
The listen port of this server (HTTP).
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
securePort int
The listen secure port of this server (HTTPS).
finalinherited
serverName String
The server header value.
no setterinherited
serverResponseDelay Duration?
A forced delay in each server response. Only active if development is true.
finalinherited
staticFilesCacheControl String
The cache-control header for static files.
finalinherited
staticFilesCacheMaxContentLength int
The maximum Content-Length (in bytes) allowed for a cached Response. Default: 10M
finalinherited
staticFilesCacheMaxMemorySize int
The maximum memory size (in bytes) for storing all cached Responses. Default: 50M
finalinherited
totalWorkers int
The number of APIServerWorker instances to spawn.
finalinherited
url String
The local URL of this server.
no setterinherited
urlHost String
The host of url;
no setterinherited
useSessionID bool
If true the server will use/generate a SESSIONID for each request. If false will ignore any SESSIONID cookie (useful to comply with cookieless servers).
finalinherited
version String
The version of this server.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() Future<bool>
Starts this server.
inherited
stop() Future<void>
Stops/closes this server.
inherited
toJson() Map<String, dynamic>
inherited
toString() String
A string representation of this object.
override
waitStopped() Future<bool>
Returns a Future that completes when this server stops.
inherited

Operators

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

Static Properties

exposeHeaders String
final
headerXAccessToken String
final
headerXAccessTokenExpiration String
final

Static Methods

create(APIRoot apiRoot, [List<String> args = const <String>[], int argsOffset = 0]) APIServer
Creates an APIServer with apiRoot.
getOrigin(APIRequest request) String
resolveBestTextMimeType(String text, [String? fileExtension]) String
resolveBody(dynamic payload, APIResponse apiResponse) FutureOr<Object?>
Resolves a payload to an HTTP body (accepts payload as a Future). See resolveBodySync.
resolveBodySync(dynamic payload, APIResponse apiResponse) Object?
Resolves a payload to an HTTP body (Does NOT accept payload as a Future). See resolveBody.
resolveServerTiming(Map<String, APIMetric> metrics) String
run(APIRoot apiRoot, List<String> args, {int argsOffset = 0, bool verbose = false}) Future<APIServer>
Runs apiRoot and returns the APIServer.
setCORS(APIRequest request, APIResponse response) → void
toAPIRequest(Request request, {required bool cookieless, required bool useSessionID}) FutureOr<APIRequest>
Converts a request to an APIRequest.