Skip to content

Commit

Permalink
Merge pull request #2 from arcticfox1919/dart3
Browse files Browse the repository at this point in the history
Dart3
  • Loading branch information
arcticfox1919 committed Jun 24, 2023
2 parents 12b41d4 + 61909de commit 16dbdb3
Show file tree
Hide file tree
Showing 23 changed files with 2,097 additions and 1,398 deletions.
16 changes: 13 additions & 3 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
## 0.0.1

- Initial version, created by Stagehand
## 0.1.0
- Upgrade to dart 3.x support
- Added a websocket handler that can be used to provide websocket services
- Added a static file serving handler to serve files
- Fixed the error reporting for dart 3 isolate concurrency support

## 0.0.2

- Fix dart version 3 error reporting

## 0.0.1

- Initial version, created by Stagehand
238 changes: 136 additions & 102 deletions README.md
@@ -1,102 +1,136 @@

# arowana


![](https://gitee.com/arcticfox1919/ImageHosting/raw/master/img/2021-10-17-002.png)


A lightweight HTTP server framework for Dart.It is based on the [shelf](https://github.com/dart-lang/shelf) library for handling HTTP requests and implements a high-performance routing with reference to Golang's Gin framework.

It can be used in Flutter and run to mobile platforms.

## Usage

A simple usage example:

```dart
import 'dart:isolate';
import 'package:arowana/arowana.dart';
class MyAChannel extends DefaultChannel{
@override
Future prepare() {
print('current isolate [${Isolate.current.debugName}]');
return super.prepare();
}
@override
void entryPoint() {
get('/hello', (r){
return Response.ok('hello,arowana!');
});
}
}
void main() {
var app = Application(MyAChannel());
app.start(numberOfInstances: 2,consoleLogging: true);
}
```
Another example, containing grouped routes:
```dart
class MyAChannel extends AppChannel {
Router app = Router();
Middleware verification() => (innerHandler) {
return (request) async {
if (request.query['name'] == 'abc' &&
request.query['pass'] == '123') {
return await innerHandler(request);
} else {
return ResponseX.unauthorized('Authentication failed !!!');
}
};
};
@override
void entryPoint() {
var r1 = app.group('/v1');
// var middleware = Pipeline().addMiddleware(verification()).middleware;
r1.use(verification());
r1.get('/hello', (Request request) {
return Response.ok('hello-world');
});
r1.get('/greet/:name', (Request request, String name) {
return Response.ok('Hi,$name');
});
var r2 = app.group('/v2');
r2.get('/hello', (Request request) {
return Response.ok('hello,arowana');
});
r2.get('/user/:name', (Request request, String user) {
return Response.ok('hello, $user');
});
}
@override
FutureOr<Response> call(Request request) {
print('current isolate [${Isolate.current.debugName}]');
return app.call(request);
}
}
void main() {
var app = Application(MyAChannel());
app.options = ApplicationOptions()..address = '127.0.0.1';
app.start(numberOfInstances: 2,consoleLogging: true);
}
```

## Example
It has a complete example of authentication, visit [here](https://github.com/arcticfox1919/auth-server).

## Features and bugs

Please file feature requests and bugs at the [issue tracker][tracker].

[tracker]: http://example.com/issues/replaceme

# arowana


![](https://gitee.com/arcticfox1919/ImageHosting/raw/master/img/2021-10-17-002.png)


A lightweight HTTP server framework for Dart.It is based on the [shelf](https://github.com/dart-lang/shelf) library for handling HTTP requests and implements a high-performance routing with reference to Golang's Gin framework.

It can be used in Flutter and run to mobile platforms.

## Usage

A simple usage example:

```dart
import 'dart:isolate';
import 'package:arowana/arowana.dart';
class MyAChannel extends DefaultChannel{
@override
Future prepare() {
print('current isolate [${Isolate.current.debugName}]');
return super.prepare();
}
@override
void entryPoint() {
get('/hello', (r){
return Response.ok('hello,arowana!');
});
}
}
void main() {
var app = Application(() => MyAChannel(''));
app.start(numberOfInstances: 2,consoleLogging: true);
}
```
Another example, containing grouped routes:
```dart
class MyAChannel extends AppChannel {
Router app = Router();
Middleware verification() => (innerHandler) {
return (request) async {
if (request.query['name'] == 'abc' &&
request.query['pass'] == '123') {
return await innerHandler(request);
} else {
return ResponseX.unauthorized('Authentication failed !!!');
}
};
};
@override
void entryPoint() {
var r1 = app.group('/v1');
// var middleware = Pipeline().addMiddleware(verification()).middleware;
r1.use(verification());
r1.get('/hello', (Request request) {
return Response.ok('hello-world');
});
r1.get('/greet/:name', (Request request, String name) {
return Response.ok('Hi,$name');
});
var r2 = app.group('/v2');
r2.get('/hello', (Request request) {
return Response.ok('hello,arowana');
});
r2.get('/user/:name', (Request request, String user) {
return Response.ok('hello, $user');
});
}
@override
FutureOr<Response> call(Request request) {
print('current isolate [${Isolate.current.debugName}]');
return app.call(request);
}
}
void main() {
var app = Application(() => MyAChannel(''));
app.options = ApplicationOptions()..address = '127.0.0.1';
app.start(numberOfInstances: 2,consoleLogging: true);
}
```

> Upgrade to 0.1.0:
> You can create websocket serving and static file serving
```dart
final class MyWebSocket extends WebSocketController{
MyWebSocket() : super(null,null,null);
@override
void onConnection(WebSocketChannel webSocket, String? protocol) {
webSocket.stream.listen((message) {
webSocket.sink.add('echo $message');
});
}
}
```

register:
```dart
@override
void entryPoint() {
get('/hello', (r) async {
return Response.ok('hello,arowana! form:${Isolate.current.debugName}');
});
get('/ws', MyWebSocket());
// visit http://127.0.0.1:8888/example/example.dart
get('/example/*path', createStaticHandler('.'));
}
```




## Example
It has a complete example of authentication, visit [here](https://github.com/arcticfox1919/auth-server).

## Features and bugs

Please file feature requests and bugs at the [issue tracker][tracker].

[tracker]: http://example.com/issues/replaceme
112 changes: 58 additions & 54 deletions example/example.dart
@@ -1,54 +1,58 @@
import 'dart:async';
import 'dart:isolate';

import 'package:arowana/arowana.dart';

class MyAChannel extends AppChannel {
Router app = Router();

Middleware verification() => (innerHandler) {
return (request) async {
if (request.query['name'] == 'abc' &&
request.query['pass'] == '123') {
return await innerHandler(request);
} else {
return ResponseX.unauthorized('Authentication failed !!!');
}
};
};

@override
void entryPoint() {
var r1 = app.group('/v1');

// var middleware = Pipeline().addMiddleware(verification()).middleware;
r1.use(verification());
r1.get('/hello', (Request request) {
return Response.ok('hello-world');
});

r1.get('/greet/:name', (Request request, String name) {
return Response.ok('Hi,$name');
});

var r2 = app.group('/v2');
r2.get('/hello', (Request request) {
return Response.ok('hello,arowana');
});
r2.get('/user/:name', (Request request, String user) {
return Response.ok('hello, $user');
});
}

@override
FutureOr<Response> call(Request request) {
print('current isolate [${Isolate.current.debugName}]');
return app.call(request);
}
}

void main() {
var app = Application(MyAChannel());
app.options = ApplicationOptions()..address = '127.0.0.1';
app.start(numberOfInstances: 2,consoleLogging: true);
}
import 'dart:async';
import 'dart:isolate';

import 'package:arowana/arowana.dart';

base class MyAChannel extends AppChannel {
MyAChannel(String a);

Router app = Router();

Middleware verification() => (innerHandler) {
return (request) async {
if (request.query['name'] == 'abc' &&
request.query['pass'] == '123') {
return await innerHandler(request);
} else {
return Response.unauthorized('Authentication failed !!!');
}
};
};

@override
void entryPoint() {
var r1 = app.group('/v1');

// var middleware = Pipeline().addMiddleware(verification()).middleware;
r1.use(verification());
r1.get('/hello', (Request request) {
return Response.ok('hello-world');
});

r1.get('/greet/:name', (Request request, String name) {
return Response.ok('Hi,$name');
});

var r2 = app.group('/v2');
r2.get('/hello', (Request request) {
return Response.ok('hello,arowana');
});
r2.get('/user/:name', (Request request, String user) {
return Response.ok('hello, $user');
});
}

@override
FutureOr<Response> call(Request request) {
print('current isolate [${Isolate.current.debugName}]');
return app.call(request);
}
}

void main() {
var app = Application(() => MyAChannel(''));
app.options = ApplicationOptions()
..port = 49218
..address = '127.0.0.1';
app.start(numberOfInstances: 2, consoleLogging: true);
}

0 comments on commit 16dbdb3

Please sign in to comment.