Download the PHP package spatial/route without Composer

On this page you can find all versions of the php package spatial/route. 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 route

Spatial Route - Robost request router for PHP

Set defaultContentType(), enableCache(), allowedMethods(), controllerNamespaceMap(), and authGuard() to list Authorization(CanActivate Interface) Objects

Routing is responsible for mapping request URIs to endpoint selectors and dispatching incoming requests to endpoints. Routes are defined in the app and configured when the app starts. A route can optionally extract values from the URL contained in the request, and these values can then be used for request processing. Using route information from the app, routing is also able to generate URLs that map to endpoint selectors.

Install

You should install Route with Composer:

Requires PHP 7.4 or newer.

Routing Basic

Most apps should choose a basic and descriptive routing scheme so that URLs are readable and meaningful. The default conventional route {controller=Home}/{action=Index}/{id?}:

Supports a basic and descriptive routing scheme. Is a useful starting point for UI-based apps. Developers commonly add additional terse routes to high-traffic areas of an app in specialized situations (for example, blog and ecommerce endpoints) using attribute routing or dedicated conventional routes.

Web APIs should use attribute routing to model the app's functionality as a set of resources where operations are represented by HTTP verbs. This means that many operations (for example, GET, POST) on the same logical resource will use the same URL. Attribute routing provides a level of control that's needed to carefully design an API's public endpoint layout.

Usage

In Spatial Web API, a controller is a class that handles HTTP requests. The public methods of the controller are called action methods or simply actions. When the Web API framework receives a request, it routes the request to an action.

To determine which action to invoke, the framework uses a routing table.

Each entry in the routing table contains a route template. The set route template for Spatia-Route is "api/{controller}/{id}". In this template, "api" is a literal path segment, and {controller} and {id} are placeholder variables.

When the library receives an HTTP request, it tries to match the URI against one of the route templates in the routing table. If no route matches, the client receives a 404 error. For example, the following URIs match the default route:

Once a matching route is found, Spatia-Route selects the controller and the action:

To find the controller, Spatia-Route adds "Controller" to the value of the {controller} variable. To find the action, Spatia-Route looks at the HTTP verb, and then looks for an action whose name begins with that HTTP verb name. For example, with a GET request, Spatia-Route looks for an action prefixed with "Get", such as "GetContact" or "GetAllContacts". This convention applies only to GET, POST, PUT, DELETE, HEAD, OPTIONS, and PATCH verbs. (You can enable other HTTP verbs by using attributes on your controller -- future update). We'll see an example of that later. Other placeholder variables in the route template, such as {id}, are mapped to action parameters. Let's look at an example. Suppose that you define the following controller:

Here are some possible HTTP requests, along with the action that gets invoked for each: HTTP Verb URI Path Method / Action Parameter
GET api/products httpGet (none)
GET api/products/4 httpGet 4
DELETE api/products/4 httpDelete 4
POST api/products (no match)

Notice that the {id} segment of the URI, if present, is mapped to the id parameter of the action. In this example, the controller defines GET method, one with an id parameter.

Also, note that the POST request will fail, because the controller does not define a "Post..." method.

Routing by Action Name

With the default routing template, Web API uses the HTTP verb to select the action. However, you can also create a route where the action name is included in the URI:

In this route template, the {action} parameter names the action method on the controller.

Defining route{Templates}

The routes are defined by calling the Spatial\Router\RouterModule->routeConfig() function, which accepts a callable taking a Spatial\Router\Route instance. The routes are added by calling mapRoute() on the collector instance:

The $name is a camelcase HTTP method string for which a certain route should match. It is possible to specify multiple valid methods using an array:

In the case of having a placeholder in the routeTemplate like so: suiteapi/{controller}/public/{...param}. the three character ... prefixing a placeholder must always be placed at the end of the routeTemplate string since it represents an array list of the rest of the URI starting from that its index.

Example

Say we have a route

And its associate controller

Here are some possible HTTP requests, along with the action that gets invoked for each: HTTP Verb URI Path Method / Action Paramter
GET api/products httpGet null
GET api/products/4 httpGet 4
GET api/products/4/category/7 httpGet [4,'category',7]
POST api/products httpPost string $content

Credits

This library is based on a router in the dotNetCore WebAPI Framework


All versions of route with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4
psr/http-message Version ^1.0
spatial/psr7 Version ^1.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 spatial/route contains the following files

Loading the files please wait ....