All Projects → noodlehaus → Dispatch

noodlehaus / Dispatch

a tiny library for quick and easy PHP 5.6+ apps

Projects that are alternatives of or similar to Dispatch

Grip
The microframework for writing powerful web applications.
Stars: ✭ 137 (-74.39%)
Mutual labels:  microframework, router
Router
🛣 Simple Navigation for iOS
Stars: ✭ 438 (-18.13%)
Mutual labels:  microframework, router
Joi Router
Configurable, input and output validated routing for koa
Stars: ✭ 418 (-21.87%)
Mutual labels:  router
React Router Navigation
⛵️ A complete navigation library for React Native, React DOM and React Router
Stars: ✭ 498 (-6.92%)
Mutual labels:  router
Frdintent
A framework for handle the call between view controllers in iOS
Stars: ✭ 479 (-10.47%)
Mutual labels:  router
Auto route library
Flutter route generator
Stars: ✭ 434 (-18.88%)
Mutual labels:  router
Httptreemux
High-speed, flexible tree-based HTTP router for Go.
Stars: ✭ 484 (-9.53%)
Mutual labels:  router
Routersdk
A mini and excellent Router Framwork一款小而美的路由框架。网页动态添加自定义参数启动应用。 https://github.com/Jomes/routerSDK
Stars: ✭ 402 (-24.86%)
Mutual labels:  router
React Router Page Transition
Highly customizable page transition component for your React Router
Stars: ✭ 531 (-0.75%)
Mutual labels:  router
Next Connect
The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
Stars: ✭ 454 (-15.14%)
Mutual labels:  router
Gorouter
xujiajun/gorouter is a simple and fast HTTP router for Go. It is easy to build RESTful APIs and your web framework.
Stars: ✭ 496 (-7.29%)
Mutual labels:  router
Gearbox
Gearbox ⚙️ is a web framework written in Go with a focus on high performance
Stars: ✭ 455 (-14.95%)
Mutual labels:  router
Mux
A high performance and powerful trie based url path router for Go.
Stars: ✭ 487 (-8.97%)
Mutual labels:  router
Heavenlymodule
基于rxjava retrofit封装的框架
Stars: ✭ 428 (-20%)
Mutual labels:  router
Zikrouter
Interface-oriented router for discovering modules, and injecting dependencies with protocol in Objective-C and Swift.
Stars: ✭ 516 (-3.55%)
Mutual labels:  router
Portmapper
A tool for managing port forwardings via UPnP
Stars: ✭ 416 (-22.24%)
Mutual labels:  router
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+3934.95%)
Mutual labels:  router
Uni Simple Router
a simple, lightweight routing plugin that supports interception and lifecycle triggering
Stars: ✭ 481 (-10.09%)
Mutual labels:  router
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+0%)
Mutual labels:  router
Kapow
Kapow! If you can script it, you can HTTP it.
Stars: ✭ 526 (-1.68%)
Mutual labels:  microframework

dispatch

  • a tiny library for quick and easy PHP apps
  • requires PHP 5.6+

Here's a sample of how you'd usually use dispatch.

<?php

require 'path/to/dispatch.php';

# sample JSON end point
route('GET', '/books.json', function ($db, $config) {
  $list = loadAllBooks($db);
  $json = json_encode($list);
  return response($json, 200, ['content-type' => 'application/json']);
});

# html end point
route('GET', '/books/:id', function ($args, $db) {
  $book = loadBookById($db, $args['id']);
  $html = phtml(__DIR__.'/views/book', ['book' => $book]);
  return response($html);
});

# respond using a template
route('GET', '/about', page(__DIR__.'/views/about'));

# sample dependencies
$config = require __DIR__.'/config.php';
$db = createDBConnection($config['db']);

# arguments you pass here get forwarded to the route actions
dispatch($db, $config);

If you want to see where all the state goes, you can use action and serve.

<?php

require 'path/to/dispatch.php';

# create a stack of actions
$routes = [
  action('GET', '/books.json', function ($db, $config) {
    $list = loadAllBooks($db);
    $json = json_encode($list);
    return response($json, 200, ['content-type' => 'application/json']);
  }),
  action('GET', '/books/:id', function ($args, $db) {
    $book = loadBookById($db, $args['id']);
    $html = phtml(__DIR__.'/views/book', ['book' => $book]);
    return response($html);
  }),
  action('GET', '/about', page(__DIR__.'/views/about'))
];

# sample dependencies
$config = require __DIR__.'/config.php';
$db = createDBConnection($config['db']);

# we need the method and requested path
$verb = $_SERVER['REQUEST_METHOD'],
$path = $_SERVER['REQUEST_URI'],

# serve app against verb + path, pass dependencies
$responder = serve($routes, $verb, $path, $db, $config);

# invoke responder to flush response
$responder();

tests

Tests for dispatch use plain assertions.

php tests/dispatch-tests.php

If no errors were printed, then you're all good.

license

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].