Download the PHP package weblove/wp-router without Composer

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

Wordpress router logo

Wordpress REST API router library

MIT license size version open issues

Easily write modern and reusable route middlewares for your Wordpress projects and plugins. WPRouter is inspired from the excellent expressJs javascript framework. Working with Wordpress REST API will now bring you joy - instead of pain.

See on:

Getting started

You need to have Composer installed on your machine, follow this link for instructions on how to install Composer.

Prerequisites

Installing

The best way to install this library is with composer:

Basic example

The $request function param implements Wordpress WP_REST_Request class. The $response param is an empty variable that can be used to pass data to the next middleware down the chain, or to send back data on your endpoint.

Creating your first middleware

Creating a middleware is a breeze. Create an anonymous function with $request and $response as parameters. A middleware custom middleware can return any type of data that is JSON serializable or an instance of WP_REST_Request

Returning early

If you want to break your request early, you can return an instance of WP_REST_Request as a response and the router will block executing subsequent middlewares and return that response. This can be very useful to send back errors to the API:

Chaining middlewares

Just like expressJS, you can chain middlewares one after the other. The Router methods can take many functions as parameters. The $response body is simply passed to the next middleware down the chain. You can use this pattern to isolate logic in small and easy to test functions that have a single purpose:

Hook on an existing wordpress REST endpoint

You can also modify the response body of an existing wordpress endpoint with the public hook() method. Middlewares added to the hook handler will have a pre-filled $response parameter with the array that Wordpress would normally return to the client. You can easily modify the response before returning.

A hook request MUST end with a WP_REST_Response class, it is possible to pass custom $request objects from middleware to middleware, however your last middleware (or your early breaks) must always be an instance of WP_REST_Request. This way you make certain that other plugins that interops with the REST API will keep working properly.

note: You do not need to put /wp-json in your endpoint address.

Customize the default directory

By default your routes get added under the /wp-json/api directory. You can change the default behavior by providing a router parameter to the Router class:

Public methods

Troubleshooting and frequent errors

Authors

License

This project is licensed under the MIT License - see the license.md file for details.


All versions of wp-router with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.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 weblove/wp-router contains the following files

Loading the files please wait ....