cruky 0.1.0 copy "cruky: ^0.1.0" to clipboard
cruky: ^0.1.0 copied to clipboard

discontinuedreplaced by: croky
outdated

cruky is server-side library to create API with modern and fast performance.

example/main.dart

library todos; // library must be added and unique to add all routes in it

import 'package:cruky/cruky.dart';

List<Map> todos = [
  {"id": 1, "task": "task 1"},
  {"id": 2, "task": "task 2"},
];

/// serving the routes to http server
/// with hot reloading.
///
/// without hotreload:
/// ```dart
/// void main() => serve();
/// ```
void main() => serveWithHotReload();

@Route.get('/todos/list/')
Future<List> listTodos(SimpleRequest request) async => [...todos];

/// get the id from path parameters you can define `:id(int)` or `:id(string)` or `:id(double)`
/// , the parameter formate is `:nameOfField(type)` and the type is optional the default is string
@Route.get('/todos/:id(int)/')
Future<Map> getTodo(SimpleRequest request) async => {...todos[request['id']]};

/// get the task from form, there is two ways two to define request form type.
///
/// First is `FormRequest` form regular form request
/// , And secons is `iFormRequest` for multipart form
@Route.post('/todos/')
Future<List> createTodo(FormRequest request) async {
  Map newTodo = {"id": todos.length + 1};
  newTodo.addAll({"task": request['task']});
  todos.add(newTodo);
  return todos;
}

/// get the id fro path parameters
@Route.delete('/todos/:id(int)')
Map deleteTodo(SimpleRequest request) {
  todos.removeAt(request['id']);

  /// return custom status code
  return {
    #status: HttpStatus.ok,
    #body: {"msg": "the todo is deleted"}
  };
}
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

cruky is server-side library to create API with modern and fast performance.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

mime, watcher

More

Packages that depend on cruky