simple_rest 0.4.0 copy "simple_rest: ^0.4.0" to clipboard
simple_rest: ^0.4.0 copied to clipboard

discontinued
outdated

Get your REST API server up and running in no time with our user-friendly quickstart package, designed for easy initialization in just a few simple steps.

simple_rest #

pub.dev logo

License: MIT simple_rest

simple_rest is a Dart package that provides a simple way to create RESTful APIs in Dart. #

Installation #

To install simple_rest, add the following dependency to your pubspec.yaml file:

dependencies:
  simple_rest: ^0.4.0

Or just type on console:

dart pub add simple_rest

Then run dart pub get on the command line.

Use #

import 'package:simple_rest/simple_rest.dart';

Estructura (Opcional) #

Initially, the example suggests a folder structure to follow some best practices when building the system, but you can structure it however you prefer.

model
crud
repository
service
controller
main.dart

Initially, you should create your model and its CRUD methods.

/// Call the methods we need and use them in our controller functions.
/// Declare controller using [RestController] + path
/// USE:
/// GetMapping
/// PostMapping
/// DeleteMapping
/// PatchMapping
/// PutMapping
@RestController('/school')
class SchoolController {

  @GetMapping(path: '/id/<number>')
  Map<String, dynamic> printSchoolIdWithNumber(@PathVariable('number') dynamic number) {
    return {'name': 'Name School', 'number': number};
  }

  @GetMapping(path: '/apellido/<ape>')
  Map<String, dynamic> printSchoolIdWithName2(@PathVariable('ape') dynamic name) {
    return {'address': 'J 23 Remuerandia', 'apellido': name};
  }

  @GetMapping(path: '/name/<name>')
  Map<String, dynamic> printSchoolIdWithName(@PathVariable('name') dynamic name) {
    return {'address': 'J 23 Remuerandia', 'school': name};
  }

  @PostMapping(path: '/')
  List<Map<String, dynamic>> saveSchool(@BodyAttribute('body') dynamic bodyData) {
    Map<String, dynamic> moreInfo = {
      "school": "san jose"
    };

    var dataSchool = jsonDecode(bodyData );
    return [
      moreInfo,
      dataSchool
    ];
  }

  @DeleteMapping(path: '/id/<id>')
  Map<String, dynamic> deleteSchool(@PathVariable('id') String id){

    List<String> dates = ['jhon','juan','pedro'];
    dates.remove(id);

    return {
      "names": dates
    };
  }

  @PatchMapping(path: '/')
  Map<String, dynamic> updateSchool(@BodyAttribute('body') dynamic body){
    var dataSchool = jsonDecode(body );
    return dataSchool;
  }


  @PutMapping(path: '/')
  Map<String, dynamic> updateSchoolComplete(@BodyAttribute('body') dynamic body){
    var dataSchool = jsonDecode(body );
    return dataSchool;
  }



}

For initialize our server as follows and Just register the controllers on controllerList.

void main() {

  Router  app = Router();
  SServer server = SServer();

  server.start(
    port:  8080,
    isRouterControlActive: false,
    app: app,
    controllerList: [
      SchoolController
    ],
  );


}

This is how our server will be initialized and in my case, we can use our server as localhost on port 8080 with the endpoint user/all, which would look like this."https://localhost:8080/user/al"

server_inicialization.png

using endpoint.png

Additional Notes. #

This mini library was created with only one purpose in mind - to be able to quickly and easily initialize your backend. That's why I made sure to use as few libraries as possible. This makes it lightweight and powerful, which improves the performance of our API. I tried to make the library easy to implement.

As a developer, you will likely find redundancy in some parts of the code, so I would appreciate it if you inform me in the most polite way possible. Remember, we can grow together 😘.

1
likes
0
points
6
downloads

Publisher

verified publisherjhonacode.com

Weekly Downloads

Get your REST API server up and running in no time with our user-friendly quickstart package, designed for easy initialization in just a few simple steps.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, logger, mime, shelf, shelf_cors_headers, shelf_router

More

Packages that depend on simple_rest