67 lines
1.3 KiB
Dart
67 lines
1.3 KiB
Dart
|
|
abstract class WebServer {
|
|
static late WebServer _webServer;
|
|
|
|
static WebServer getInstance() {
|
|
return _webServer;
|
|
}
|
|
|
|
static void setInstance(WebServer server) {
|
|
_webServer = server;
|
|
}
|
|
|
|
void start(int port, {Function? interceptor});
|
|
void stop();
|
|
void addHandler(handler);
|
|
}
|
|
|
|
enum HttpMethod {
|
|
GET,
|
|
POST,
|
|
PUT,
|
|
DELETE,
|
|
ALL,
|
|
WS,
|
|
;
|
|
|
|
static HttpMethod valueOf(String type) {
|
|
var tmp = HttpMethod.values.where((t) => t.name == type).toList();
|
|
if (tmp.isEmpty) {
|
|
return HttpMethod.ALL;
|
|
}
|
|
return tmp[0];
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
static HttpResponseType valueOf(String type) {
|
|
var tmp = HttpResponseType.values.where((t) => t.type == type).toList();
|
|
if (tmp.isEmpty) {
|
|
return HttpResponseType.JSON;
|
|
}
|
|
return tmp[0];
|
|
}
|
|
}
|
|
|
|
class RequestMapping {
|
|
final HttpMethod method;
|
|
final String path;
|
|
final HttpResponseType responseType;
|
|
|
|
const RequestMapping(
|
|
{this.method = HttpMethod.ALL,
|
|
required this.path,
|
|
this.responseType = HttpResponseType.JSON});
|
|
}
|