server side dart micro-framework to handle incoming http requests

Overview

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

  • register routes and the call back for each route
  • use guards 'palace.use(CORSGuard())' for example
  • open the server
  • close the server

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

  • res.json(data?) will convert the given data to JSON and sent it back to the user
  • res.file(path) give it path and it will give the file to the user
  • res.notFound(data?) => 404
  • res.internalServerError(data?) => 500
  • res.accepted(data?) => 200
  • res.created(data?) => 201

and so on....

Middleware aka Guard 💂‍♂️

a simple function

  • return void
  • takes any parameters you want starting from 0 parameters or the entire parameters list (see the parameters list down below)
  • guards considered as extra layer before the Handlers layers
  • they can be registered for specific route or as global guard for any kind of requests
  • they can response to incoming requests since they have access to the incoming request
  • they can preform any kind of logic before or after the handler be triggered

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

  • here some of them
  • BadRequest(data?)
  • NotFound(data?)
  • Unauthorized(data?)

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

  • without decorations you can get access to the incoming request or the response by declaring the type of them
  @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

You might also like...

Modular server framework with ConnectMe (WebSockets + PackMe) and MongoDb support.

What is ServeMe ServeMe is a simple and powerful modular server framework. It allows to easily create backend services for both mobile and web applica

Dec 3, 2022

✈️ A tidy utility to handle offline/online connectivity like a Boss

✈️ A tidy utility to handle offline/online connectivity like a Boss

✈️ Flutter Offline A tidy utility to handle offline/online connectivity like a Boss. It provides support for both iOS and Android platforms (offcourse

Jan 2, 2023

Flutter Radio Player, A Plugin to handle streaming audio without a hassle

Flutter Radio Player, A Plugin to handle streaming audio without a hassle

Flutter radio plugin handles a single streaming media preciously. This plugin was developed with maximum usage in mind. Flutter Radio player enables S

Dec 27, 2022

This repo contains the side menu UI for admin template

f9tech A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this i

Dec 11, 2021

Flutter application for meditell admin side

meditell_admin Flutter application for meditell admin side Getting Started This project is a starting point for a Flutter application. A few resources

Nov 24, 2021

Concepts used Flutter layout,State management, Blockchain integration, Http api integration, Smart contracts

HS_CryptoCoin_Wallet First project using Flutter with Blockchain Getting Started This project is a starting point for a Flutter application. A few res

Dec 23, 2021

Easy way to store http response.

Easy way to store http response.

Starlight Http Cached The easiest way to store data such as http response,String,int,double,bool,map,list. Features ☑️ Set Cached ☑️ Get Cached ☑️ Del

Jan 9, 2023

Chopper is an http client generator using source_gen and inspired from Retrofit.

Chopper is an http client generator using source_gen and inspired from Retrofit.

Chopper Chopper is an http client generator for Dart and Flutter using source_gen and inspired by Retrofit. Documentation Installation Please refer to

Dec 31, 2022

This project is a implementation of a collection of terminal server samples in Dart

Terminal Server Samples ⭐ Star me on GitHub — it helps! This project is a implementation of a collection of terminal server samples in Dart licensed u

Nov 26, 2021
Releases(0.0.1+1)
Owner
Ahmed Masoud
Ahmed Masoud
Fetchx - Simplified http requests in Dart

Fetchx Fetchx is a simple, fast, and secure HTTP client for Dart. It leverages extensions to allow using url-like strings to make http requests. Read

Brian Omondi 9 Nov 26, 2022
Dart HTTP server framework for building REST APIs. Includes PostgreSQL ORM and OAuth2 provider.

Aqueduct is a modern Dart HTTP server framework. The framework is composed of libraries for handling and routing HTTP requests, object-relational mapp

Stable Kernel 2.4k Jan 5, 2023
Simple examples that help you get started with Appwrite + Dart (=❤️) as an Appwrite server-side integration.

Playground for Dart Simple examples that help you get started with Appwrite + Dart (= ❤️ ) This is Appwrite server side integration with Dart. For Flu

Appwrite 31 Nov 22, 2022
Server-side timer project using WebSockets(with Socket.IO), NestJS and Flutter

Documentation Full documentation and the article series can be found here, Article on dev.to Output Setup Run Locally Clone the project git clone ht

Rukshan J. Senanayaka 9 Dec 26, 2022
Petit httpd - This is a simple HTTP file server integrated with Let's Encrypt, gzip and CORS

Petit httpd - This is a simple HTTP file server integrated with Let's Encrypt, gzip and CORS

Graciliano Monteiro Passos 4 Nov 24, 2022
Dart/Flutter package for using Elastic App Search through a simple API returning easy to handle objects

Dart/Flutter package for using Elastic App Search through a simple API returning easy to handle objects This package is a ready-to-use API for Elastic

Julien Le Bren 5 Nov 16, 2022
App for sending ssh requests. Wake on Lan through ssh

wakeonwears WakeOnLan through ssh Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Sergey Latu 1 Oct 15, 2021
Rokeet UI - A Server Driven UI Framework

Rokeet UI A Server-Driven UI framework. Status Lib Build Coverage Core Configure Mockoon server Install Mockoon: Mac OSX brew install --cask mockoon

osodroid 6 Apr 7, 2022
A Flutter server rendering framework

Shark Flutter ?? (Under Construction) A Flutter server rendering framework After i finish the project structure, I would draw a project diagram and de

Vau 62 Dec 29, 2022
A performant, expressjs like server framework with a few gadgets that make life even easier.

Alfred A performant, expressjs like server framework thats easy to use and has all the bits in one place. Quickstart: import 'package:alfred/alfred.da

Ryan Knell 449 Jan 2, 2023