bones_api 1.0.4 copy "bones_api: ^1.0.4" to clipboard
bones_api: ^1.0.4 copied to clipboard

outdated

Bones_API - Simple and easy API framework, with routes and HTTP Server.

Bones_API #

pub package Null Safety Codecov CI GitHub Tag New Commits Last Commits Pull Requests Code size License

Bones_API - Simple and easy API framework, with routes and HTTP Server.

Usage #

A simple usage example:

import 'package:bones_api/bones_api.dart';
import 'package:bones_api/src/bones_api_server.dart';

void main() async {
  var api = MyAPI();

  // Calling the API directly:
  var r1 = await api.call(APIRequest.get('/service/base/foo'));
  print(r1);
  
  // Serving the API trough a HTTP Server:
  var apiServer = APIServer(api, '*', 8088);
  
  await apiServer.start();

  print('Running: $apiServer');
  print('URL: ${apiServer.url}');
}

class MyAPI extends APIRoot {
  MyAPI() : super('example', '1.0');

  @override
  Set<APIModule> loadModules() => {MyBaseModule()};
}

class MyBaseModule extends APIModule {
  MyBaseModule() : super('base');

  @override
  String? get defaultRouteName => '404';

  @override
  void configure() {
    routes.get('foo', (request) => APIResponse.ok('Hi[GET]!'));
    routes.post(
            'foo', (request) => APIResponse.ok('Hi[POST]! ${request.parameters}'));

    routes.any('time', (request) => APIResponse.ok(DateTime.now()));

    routes.any('404',
                    (request) => APIResponse.notFound(payload: '404: ${request.path}'));
  }
}

CLI #

You can use the built-in command-line interface (CLI) bones_api.

To activate it globally:

 $> dart pub global activate bones_api

Now tou can use the CLI directly:

  $> bones_api --help

To serve an API project:

  $> bones_api serve --directory path/to/project --class MyAPIRoot

Bones_UI #

See also the package Bones_UI, a simple and easy Web User Interface Framework for Dart.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Colossus.Services #

This is an open-source project from Colossus.Services: the gateway for smooth solutions.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Artistic License - Version 2.0

27
likes
0
pub points
79%
popularity

Publisher

unverified uploader

Bones_API - Simple and easy API framework, with routes and HTTP Server.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

args, async_extension, dart_spawner, shelf

More

Packages that depend on bones_api