Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

server side framework for dart inspired by express.js

Queen Palace 🏰👑

Introduction

server side dart micro-framework to handle incoming http requests

hello world app

Future<void> main(List<String> args) async {
  final palace = Palace();
  palace.get('/greet_the_queen', (req, res) => res.send('Long Live The Queen 👑'));
  await palace.openGates();
}

hello world with decoration

decoration will help you split your code to parts or modules easily making the application easy to maintain

void main(List<String> args) async {
  final palace = Palace();
  palace.controllers([MainController()]);
  await palace.openGates();
}

class MainController extends PalaceController {
  MainController() : super('/');

  @Get()
  void greeTheQueen(Request req, Response res) {
    return res.send('Long Live The Queen 👑');
  }
}

Core Parts

Palace class

Request class

wrapper class around dart:io HttpRequest with extra functions and getters to make your life easier.

Response class

wrapper class around dart:io HttpResponse with extra functions and getters also to make the same life easier .

some of these functions are

and so on….

Middleware aka Guard 

a simple function

PalaceException class

you can throw them from any where from your application so guards can and handlers can or even the services can throw them

but what will happened then ? the palace will catch the exception format it to json including the given data object – if one was provided – and end the request life cycle

Callback Parameters

if you are using the decoration you can get extra push to your endpoint callback or the guards you can extract these type of data from the incoming request

  @Get()
  void sayHi(Request req,Response Res) {
    //logic
    }

need to aces the request body directly and strong typed ? use @Body() decorator

class SignUpBody{
  late String name;
  late String email;
  late String password;
}
  @Post()
  void signUp(Request req,Response Res,@Body() SignUpBody body) {
    //logic
    }

need to access specific value from the body ?

@Body('key') String email

the same goes for

@Query()
@QueryParam()
@Param()

if you are building a guard use

@Next()

to get access to the next callback

Download server side framework to handle incoming http requests source code on GitHub

https://github.com/maxzod/palace
Exit mobile version