Skip to content

Commit

Permalink
Merge pull request #9 from utopia-dart/refactor
Browse files Browse the repository at this point in the history
Utopia HTTP server library
  • Loading branch information
lohanidamodar committed Mar 11, 2024
2 parents 45e573b + 5201223 commit 1f23ade
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 152 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.1
## 0.1.0

- Initial version.
- Multi threaded HTTP server
- Easy to use
- Customizable
- Inbuilt dependency injection
43 changes: 17 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
# Utopia Dart Framework
# Utopia HTTP Server

**NOT READY FOR PRODUCTION**

Light and Fast Dart Framework to build awesome Dart applications. Inspired from [Utopia PHP Framework](https://github.com/utopia-php/framework).

## ⚠️ Warning!

This library is highly volatile and heavily under development.
Light and Fast Dart HTTP library to build awesome Dart server side applications. Inspired from [Utopia PHP ecosystem](https://github.com/utopia-php).

## Getting Started

First add the dependency in your pubspec.yaml

```yaml
dependencies:
utopia_framework:
git: https://github.com/utopia-dart/utopia_framework
utopia_http: ^0.1.0
```

Now, in main.dart, you can

```dart
import 'dart:io';
import 'package:utopia_framework/utopia_framework.dart';
import 'package:utopia_http/utopia_http.dart';
void main() async {
final app = App();
app
.get('/')
.inject('response')
.action((Response response) {
response.text('Hello World!');
return response;
});
final address = InternetAddress.anyIPv4;
final port = App.getEnv('PORT', 8080);
await App.serve(app, ShelfServer(address, port), threads: 3);
print("server started at ${address.address}:$port");
print('press any key to exit.');
stdin.readByteSync();
final port = Http.getEnv('PORT', 8080);
final app = Http(ShelfServer(address, port), threads: 8);
app.get('/').inject('request').inject('response').action(
(Request request, Response response) {
response.text('Hello world');
return response;
},
);
await app.start();
}
```

## Copyright and license

The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
The MIT License (MIT) [https://www.opensource.org/licenses/mit-license.php](https://www.opensource.org/licenses/mit-license.php)
10 changes: 5 additions & 5 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: utopia_framework_example
name: utopia_http_example
description: A starting point for Dart libraries or applications.
version: 1.0.0
publish_to: none
# homepage: https://www.example.com

environment:
sdk: '>=2.17.5 <3.0.0'
sdk: '>=2.17.5 <4.0.0'

dependencies:
shelf:
utopia_framework:
utopia_http:
path: ../

dev_dependencies:
lints: ^2.0.0
test: ^1.16.0
lints: ^3.0.0
test: ^1.25.2
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'dart:io';
import 'package:utopia_framework/utopia_framework.dart';
import 'package:utopia_http/utopia_http.dart';

void main() async {
final app = App();
app
.get('/')
.inject('request')
.inject('response')
.action((Request request, Response response) {
response.text('Hello world');
return response;
});
final address = InternetAddress.anyIPv4;
final port = Http.getEnv('PORT', 8080);
final app = Http(ShelfServer(address, port), threads: 8);

app.get('/').inject('request').inject('response').action(
(Request request, Response response) {
response.text('Hello world');
return response;
},
);
app
.get('/hello-world')
.inject('request')
Expand Down Expand Up @@ -71,10 +72,6 @@ void main() async {
return response;
});

final address = InternetAddress.anyIPv4;
final port = App.getEnv('PORT', 8080);
await App.serve(app, ShelfServer(address, port), threads: 8);
await app.start();
print("server started at http://${address.address}:$port");
print('press any key to exit.');
stdin.readByteSync();
}
1 change: 1 addition & 0 deletions lib/src/app_mode.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/// Application mode
enum AppMode { development, stage, production }
Loading

0 comments on commit 1f23ade

Please sign in to comment.