Download the PHP package funkybunch/simple-http-router without Composer

On this page you can find all versions of the php package funkybunch/simple-http-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 simple-http-router

2020 Update: PHP will forever have a special place in my heart, but its 2020 and I have moved onto other projects. As such this repository will no longer be maintained or updated. This repo and code will remain available for anyone to use, fork, modify to your heart's content, but should be considered "No longer supported".

Simple HTTP Router

Build Status

A simple router for HTTP requests written in PHP. Simple HTTP Router allows you to have a single point of entry for your web application or API and explicitly call different functions based on the HTTP REQUEST_METHOD and REQUEST_URI.

Installation

Simplest (Composer)

The quickest way to get up and running is to use Composer.

  1. Once you have Composer installed, initialize it in your root project directory using:

  2. Now you're all ready to start adding some dependencies. To install Simple HTTP Router:

That's it! Just make sure to autoload at the top of your code.

Complex (Manual)

Download the files in the repo and navigate to the src/ directory. These are the files you will need to include or require to get going.

You will need to include all 3 since they use a namespace and do not reference each other directly.

Keep in mind that composer will not be able to automatically update this dependency if you do a manual installation so it is highly recommended that you use Composer instead.

Usage

Once you are all setup and have everything installed, create the file you want to use as your web app/api facing file. Typically, this will be an index.php file in your web server live directory root. We'll refer to this as your router file.

Create the Router()

To get started, you need to create a new Router() object:

GET Request

To setup a route for a GET request, use the get() method in the Router() class. This method requires the $path that you are setting the route for, as well as an anonymous function(). This function() is called if the $path matches the HTTP request.

You can add as many get() methods as you need.

Here's what your index.php file might look like at this point:

POST Request

To setup a route for a POST request, use the post() method in the Router() class. Similarly to the get() method, this method requires the $path that you are setting the route for, as well as an anonymous function(). This function() is called if the $path matches the HTTP request.

Here's what your index.php file might look like at this point:

getRequest() Method

If you are building an API, you will likely need to get the body of the HTTP request. This can be done using the getRequest() method. This returns the request object for both GET and POST requests.

It is possible to use this method inside the callback function for either the get() or post() methods using a closure. For example:

The & is important because it tells PHP to use the global variable that you have already defined.

Here's what your index.php file might look like at this point:

Note: Even if Apache, or your favorite web server, is serving /var/www/mywebapp/web/ then it can still reference files in /var/www/mywebapp/. This way you can keep the rest of your application files out of a live web directory. The important part is that the file using the router is in the live directory.

Contributing & Bugs

Contributions are always welcome! Draft a pull request with any changes or improvements you make and submit it for review.

For bug reports, please create an issue and I will look into it further.

Roadmap

Please create an issue for any other suggestions.

License

Copyright (c) 2019 Mark Adkins and other contributors. This project is Open Source and licensed under the MIT License.


All versions of simple-http-router with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
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 funkybunch/simple-http-router contains the following files

Loading the files please wait ....