Download the PHP package phputil/router without Composer

On this page you can find all versions of the php package phputil/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package router

Version Build License

phputil/router

ExpressJS-like router for PHP

👉 Do NOT use it in production yet - just for toy projects.

Installation

Requires PHP 7.4+

👉 You may also like to install phputil/cors.

Notes

Examples

Hello World

Using parameters

Middleware per route

See all the examples

ℹ To help us with an example, just submit a Pull Request or open an Issue with the code.

Features

Known Middlewares

ℹ Did you create a useful middleware? Open an Issue for including it here.

API

This library does not aim to cover the entire ExpressJS API. However, feel free to contribute to this project and add more features.

Types:

Middleware

In phputil/router, a middleware is a function that:

  1. Perform some action (e.g., set response headers, verify permissions) before a route is evaluated.
  2. Can stop the router, optionally setting a response.

Syntax:

where:

Router

Class that represents a router.

get

Method that deals with a GET HTTP request.

where:

A route handler has the following syntax:

where:

Examples:

post

Method that deals with a POST HTTP request. Same syntax as get's.

put

Method that deals with a PUT HTTP request. Same syntax as get's.

delete

Method that deals with a DELETE HTTP request. Same syntax as get's.

head

Method that deals with a HEAD HTTP request. Same syntax as get's.

option

Method that deals with a OPTION HTTP request. Same syntax as get's.

patch

Method that deals with a PATCH HTTP request. Same syntax as get's.

all

Method that deals with any HTTP request. Same syntax as get's.

group

Alias to the method route.

route

Method that adds a route group, where you can register one or more HTTP method handlers.

Example:

end

Method that finishes a route group and returns to the group parent.

Example:

use

Method that adds a middleware to be evaluated before the routes declared after it.

Example:

listen

Method that executes the router.

Options are:

Example:

You can also use an instance of RouterOptions for setting the options:

RouterOptions

Options for the listen() method.

withRootURL

withReq

withRes

HttpRequest

Interface that represents an HTTP request.

API:

ExtraData

Extra, user-defined data.

HttpResponse

Interface that represents an HTTP response.

Most of its methods are chainable, that is, you can call them in a sequence. Example:

API:

Mocking an HTTP request

👉 Useful for API testing

License

Thiago Delgado Pinto


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-mbstring Version *
ext-json Version *
ext-pcre Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phputil/router contains the following files

Loading the files please wait ....