Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bryanbill/zero
Zero is a fast and lightweight Dart backend framework.
https://github.com/bryanbill/zero
api backend dart flutter
Last synced: 28 days ago
JSON representation
Zero is a fast and lightweight Dart backend framework.
- Host: GitHub
- URL: https://github.com/bryanbill/zero
- Owner: bryanbill
- License: mit
- Created: 2023-05-10T22:29:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-19T22:11:21.000Z (over 1 year ago)
- Last Synced: 2024-11-06T19:53:45.353Z (3 months ago)
- Topics: api, backend, dart, flutter
- Language: Dart
- Homepage:
- Size: 62.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Zero
Zero is a fast and lightweight **Dart** backend framework.
## Installation
Activate the Zero CLI tool:
```bash
dart pub global activate --source git https://github.com/bryanbill/zero
# Or using -sgit
dart pub global activate -sgit https://github.com/bryanbill/zero
```Create a new project:
```bash
zero new my_project
```## Usage
Run the project:
```bash
cd my_project
zero run
```## Examples
### Hello World
```dart
import 'package:zero/zero.dart';void main() {
final zero = Server(
port: 9090,
routes: [
Route(
path: '/hello',
controller: (req) => IndexController(req),
),
],
);zero.run();
print('Server running on port ${zero.port}');
}class IndexController extends Controller {
IndexController(Request request) : super(request);@Path('/')
static Response hello(Request request) {
return Response.ok('Hello world!');
}
}
```### Working with Routes, Params, Body and Query
```dart
import 'package:zero/zero.dart';class UserController extends Controller {
UserController(Request request) : super(request);// GET => /users
@Path('/')
static Future user(Request req) async{
await Future.delayed(Duration(seconds: 1));
return Response.ok('User');
}// GET => /users/:id
@Path('/:id')
@Param(['id'])
static Future userById(Request req) async{
await Future.delayed(Duration(seconds: 1));
return Response.ok('User ${req.params['id']}');
}// POST => /users
@Path('/', method: 'POST')
static Future createUser(Request req) async{
await Future.delayed(Duration(seconds: 1));
return Response.created('User created');
}
}void main(){
final zero = Server(
port: 9090,
routes: [
Route(
path: '/users',
controller: (req) => UserController(req),
),
],
);
zero.run();
print('Server running on port ${zero.port}');
}```
## Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request if you have a way to improve this project.
## License
[MIT](https://choosealicense.com/licenses/mit/)