Skip to content

Commit

Permalink
misc changes
Browse files Browse the repository at this point in the history
* Bump to 0.1.1
* Document public methods
* Update URLs
* Add basic CI
  • Loading branch information
HarryET committed Oct 22, 2021
1 parent c4c93b5 commit 792e740
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 10 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/analyze_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: analyze tests

on:
push:
pull_request:

jobs:
test-kite-http:
name: Test main nyxx package
runs-on: ubuntu-latest
steps:
- name: Cache
uses: actions/cache@v2
with:
path: ~/.pub_cache
key: ${{ runner.os }}

- name: Setup Dart Action
uses: cedx/setup-dart@v2.3.0
with:
release-channel: stable

- name: Checkout
uses: actions/checkout@v2.3.4

- name: Install dependencies
working-directory: ./
run: dart pub get

- name: Analyze project source
working-directory: ./
run: dart analyze
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
- Basic Middleware
- Basic Response Support
- Regex Based Handlers

## 0.1.1

- Add Basic CI
- Move to nyxx-discord/kite_http
- Document all public methods
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ linter:
- library_names
- library_prefixes
- non_constant_identifier_names
- only_throw_errors
- package_api_docs
- package_prefixed_library_names
- prefer_is_not_empty
Expand Down
9 changes: 4 additions & 5 deletions lib/kite_http.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
library kite_http;

import 'dart:async';
import 'dart:collection';
import 'dart:io';
import 'dart:convert' show jsonDecode, jsonEncode, utf8;
import "dart:async";
import "dart:convert" show jsonDecode, jsonEncode, utf8;
import "dart:io";

part "src/HandlerMetadata.dart";
part "src/KiteServer.dart";
part "src/Request.dart";
part "src/Response.dart";
part "src/HandlerMetadata.dart";
5 changes: 5 additions & 0 deletions lib/src/HandlerMetadata.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
part of kite_http;

/// Metadata on handlers
class HandlerMetadata {
/// The route to check for
final RegExp route;

/// The HTTP Verb to listen for
final String method;

/// Create new metadata for handler registration
const HandlerMetadata(this.route, this.method);
}
5 changes: 5 additions & 0 deletions lib/src/KiteServer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef RequestHandler = FutureOr<void> Function(
Response,
);

/// The kite_http server
class KiteServer {
late final String _hostname;
late final int _port;
Expand All @@ -22,19 +23,23 @@ class KiteServer {
final Map<HandlerMetadata, RequestHandler> _handlers =
<HandlerMetadata, RequestHandler>{};

/// Create new instace of KiteServer
KiteServer({String listen = "0.0.0.0", int port = 8080}) {
this._hostname = listen;
this._port = port;
}

/// Register middleware
void use(MiddlewareHandler handler) {
this._middleware.add(handler);
}

/// Register handler
void handle(HandlerMetadata route, RequestHandler handler) {
this._handlers[route] = handler;
}

/// Listen for incoming requests
void listen() async {
this._internalServer = await HttpServer.bind(this._hostname, this._port);

Expand Down
4 changes: 4 additions & 0 deletions lib/src/Request.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
part of kite_http;

/// Data from HTTP Request
class Request {
late final HttpRequest _internalRequest;

/// Recieved Headers
late final HttpHeaders headers;

late final Future<String> _body;
Expand All @@ -14,8 +16,10 @@ class Request {
this._body = utf8.decodeStream(this._internalRequest);
}

/// Raw String body from Request
Future<String> get body => this._body;

/// Json body from request
Future<Map<dynamic, dynamic>> get json async =>
jsonDecode(await this.body) as Map<dynamic, dynamic>;
}
3 changes: 3 additions & 0 deletions lib/src/Response.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of kite_http;

/// Controles the response for a HTTP Request
class Response {
bool _hasResponded = false;

Expand All @@ -9,6 +10,7 @@ class Response {
this._req = req;
}

/// Send a JSON response back
void json(Map<dynamic, dynamic> data, {bool throwErr = false}) {
if (this._hasResponded) {
if (throwErr) {
Expand All @@ -25,6 +27,7 @@ class Response {
this._req.response.close();
}

/// Send a string response back.
void string(String data, {bool throwErr = false}) {
if (this._hasResponded) {
if (throwErr) {
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kite_http
description: A basic HTTP server library that support json & middleware
version: 0.1.0
homepage: https://github.com/HarryET/kite
repository: https://github.com/HarryET/kite
issue_tracker: https://github.com/HarryET/kite
version: 0.1.1
homepage: https://github.com/nyxx-discord/kite_http
repository: https://github.com/nyxx-discord/kite_http
issue_tracker: https://github.com/nyxx-discord/kite_http

environment:
sdk: '>=2.13.0 <3.0.0'

0 comments on commit 792e740

Please sign in to comment.