Git Product home page Git Product logo

zero's Introduction

Zero

Zero is a fast and lightweight Dart backend framework.

Installation

Activate the Zero CLI tool:

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:

zero new my_project

Usage

Run the project:

cd my_project
zero run

Examples

Hello World

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

import 'package:zero/zero.dart';

class UserController extends Controller {
  UserController(Request request) : super(request);

  // GET => /users
  @Path('/')
  static Future<Response> user(Request req) async{
    await Future.delayed(Duration(seconds: 1));
    return Response.ok('User');
  }

  // GET => /users/:id
  @Path('/:id')
  @Param(['id'])
  static Future<Response> userById(Request req) async{
    await Future.delayed(Duration(seconds: 1));
    return Response.ok('User ${req.params['id']}');
  }

  // POST => /users
  @Path('/', method: 'POST')
  static Future<Response> 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

zero's People

Contributors

bryanbill avatar restyled-io[bot] avatar

Stargazers

Patrick waweru avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.