52 lines
892 B
Dart
52 lines
892 B
Dart
import 'dart:io';
|
|
|
|
abstract class WebServer {
|
|
static late WebServer _webServer;
|
|
|
|
static WebServer getInstance() {
|
|
return _webServer;
|
|
}
|
|
|
|
static void setInstance(WebServer server) {
|
|
_webServer = server;
|
|
}
|
|
|
|
void start(int port);
|
|
void stop();
|
|
void addHandler(handler);
|
|
}
|
|
|
|
enum HttpMethod {
|
|
GET,
|
|
POST,
|
|
PUT,
|
|
DELETE,
|
|
ALL,
|
|
WS,
|
|
;
|
|
}
|
|
|
|
enum HttpResponseType {
|
|
HTML("text/html; charset=utf-8"),
|
|
TEXT("text/plain; charset=utf-8"),
|
|
XML("text/xml; charset=utf-8"),
|
|
JSON("application/json; charset=utf-8"),
|
|
BINARY("application/octet-stream"),
|
|
;
|
|
|
|
final String type;
|
|
|
|
const HttpResponseType(this.type);
|
|
}
|
|
|
|
class RequestMapping {
|
|
final HttpMethod method;
|
|
final String path;
|
|
final HttpResponseType responseType;
|
|
|
|
const RequestMapping(
|
|
{this.method = HttpMethod.ALL,
|
|
required this.path,
|
|
this.responseType = HttpResponseType.JSON});
|
|
}
|