Download the PHP package sectoroverload2k/rest-router without Composer

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

REST Router for PHP

This code provides the basic framework for a PHP developer that wants to build a REST service.

Some of the features provided in this framework are:

Table of Contents

  1. Basic Routing
  2. Controller Structure
  3. Automatic Route Resolution
  4. Custom Routes
  5. Route Parameters
  6. Best Practices

Basic Routing

URL Structure

Example Request: GET /users/profile

How the Router Works

The REST Router will:

  1. Parse the incoming request URL
  2. Load the appropriate controller file from the /controllers directory
  3. Instantiate the controller class
  4. Call the appropriate method based on HTTP verb + action

Controller Structure

File Naming Convention

Controllers should follow your application's naming convention. Common patterns:

Class Example


Automatic Route Resolution

The router automatically resolves routes by combining the HTTP method + action name.

Simple Routes (Automatic)

These routes work without needing explicit rules in routes.php:

HTTP Request Controller Method
GET /users/profile Users->get_profile()
PUT /users/profile Users->put_profile()
DELETE /users/profile Users->delete_profile()
POST /users/create Users->post_create()

Method Naming Pattern

Examples:

Fallback Behavior

If a method-specific function is not found (e.g., get_profile()), the router will fall back to calling just the action name (e.g., profile()).


Custom Routes

When to Use Custom Routes

Use explicit routes in routes.php when:

  1. Nested paths that would be misinterpreted by automatic routing
  2. Path parameters like IDs in the middle of the URL
  3. Special routing logic that doesn't follow the standard pattern

Nested Path Example

Problem: PUT /users/profile/password

Solution in routes.php:

Order Matters!

Always define more specific routes first:


Route Parameters

Path Parameters with :parameter_name

Use :parameter_name syntax for dynamic URL segments:

Accessing Parameters in Controller

Parameters are passed to the controller method:

Multiple Parameters


Best Practices

1. Consistent Method Naming

2. Handle Request Data

3. Use Explicit Routes for Nested Paths

4. Validate Input


Complete Example

routes.php

users.php Controller


Request Methods

The REST Router supports the following HTTP methods:


All versions of rest-router with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.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 sectoroverload2k/rest-router contains the following files

Loading the files please wait ...