Coder Social home page Coder Social logo

palace's Introduction

Queen Palace ๐Ÿฐ๐Ÿ‘‘

Introduction

  • inside the palace ๐Ÿฐ you have Guards and Handlers to serve your Requests ๐Ÿ˜‰
  • batteries included ๐Ÿ”‹
    • validation including (DTO OR class) validation โš”
    • loggers (console/file) ๐Ÿ“ƒ
    • middle-wares but we preferrer to call them Guards ๐Ÿ’‚โ€โ™‚๏ธ
    • hot-reload โšก => lighthouse
    • .yaml file reader ๐Ÿจ => final dbConnection = await yaml<String>('DB_CONNECTION');

Example

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

Core Parts

Handler

type of functions that

  • return Future or void
  • takes tow arguments
    • Request req
    • Response res

a handler will be triggered when a match happened between the incoming request and the endpoint registered path

Request

wrapper class around dart HttpRequest will contains wrappers around the dart:io HttpRequest class and the httpRequest itself

Response

wrapper class around dart:io HttpResponse will have functions ease the process of responding to the incoming requests like

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

if you respond to the request you will be ending the request life cycle this means guard still will be working but they can not modify the response any more

PalaceRouter

  • register routes and the handler for each route
  • register guards
  • open the server
  • close the server

Middleware aka Guard ๐Ÿ’‚โ€โ™‚๏ธ

type of functions that

  • return Future or void

  • takes three arguments

    • Request req
    • Response res
    • Function next

guards considered as extra layer before the Handlers layers

a guard can be registered for specific route or as global guard for any kind of requests

a guard can response to incoming requests since the have access to the instance of the incoming request

a guard can preform any kind of logic before or after the handler be triggered

palace's People

Contributors

maxzod avatar spiercer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.