DChisel is simple Dart Framework for creating REST API

  API, Framework, Rest API
Dchisel Logo

DChisel Dart Framework

DChisel is simple Dart Framework for creating REST API

Features

  • Custom host server and port
  • GET, POST, PUT, DELETE, PATCH Routes
  • ORM CRUD to PostgreSQL

Usage

To add the dchisel to your Dart application read the install instructions.

Host Server

Default host is “localhost” and port 8000

import 'package:dchisel/dchisel.dart';

Future<void> main(List<String> arguments) async {
  DChisel().serve();
}

If you want to change the host to 0.0.0.0 and port to 5555 you can use :

 DChisel().serve(serverHost: '0.0.0.0', serverPort: 5555);

GET Route

DChisel().routeGet('/hello', (Request request) {
    return 'Hello, World';
});

GET with param you can use :

DChisel().routeGet('/getparam/<name>', (Request request, String name) {
    return 'Hello, $name';
});

POST Route

DChisel().routePost('/hello', (Request request) async {
    return 'Hello, World';
});

If you want to get Body value from your POST request, use :

var body = await request.body.asJson;

If you want to get Header value from your POST request, use :

var headers = await request.headers;

PUT Route

DChisel().routePut('/hello/<name>', (Request request, String name) async {
  return 'Hello, $name';
});

PUT also can get Header and Body request

var headers = await request.headers;
var body = await request.body.asJson;

DELETE Route

DChisel().routeDelete('/hello/<name>', (Request request, String name) async {
  return 'Hello, $name';
});

Dchisel ORM

For now, DChisel only support PostgreSQL

DB Config

DChiselDB().configDB(
    host: 'your_host',
    db: 'your_db_name',
    port: your_port, //integer
    username: 'your_db_username',
    password: 'your_db_password');

Get All Data

DChiselDB().getAll('your_table_name');

Get Data With Custom Column and Filter

DChiselDB().getOption('your_table_name', 
    column: 'your_column1,your_column2', 
    where: ['your_column_name', 'your_filter_value']);

If you want filter contains, just add % into your filter value, example :

'%your_filter_value%'

Create Data

DChiselDB().create('users', data: {
    'your_column_name': 'your_value'
});

Update Data

DChiselDB().update('users', data: {
    'your_column_name': 'your_value'
}, where: ['your_filter_column_name', 'your_filter_value']);

Delete Data

DChiselDB().deleteAll('your_table_name');

Delete Data Custom Filter

DChiselDB().deleteOption('your_table_name', where: ['your_filter_column_name', 'your_filter_value']);

Download source code on GitHub

https://github.com/alalawy/DChisel