PHPackages                             vogon101/dynamic-endpoints - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. vogon101/dynamic-endpoints

ActiveLibrary[API Development](/categories/api)

vogon101/dynamic-endpoints
==========================

Super-Simple framework for making nice PHP APIs

1.0.2(10y ago)1181PHPPHP &gt;=5.3.0

Since Apr 15Pushed 10y ago2 watchersCompare

[ Source](https://github.com/vogon101/DynamicEndpoints)[ Packagist](https://packagist.org/packages/vogon101/dynamic-endpoints)[ Docs](https://github.com/BluePost/BlueAjax/)[ RSS](/packages/vogon101-dynamic-endpoints/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

DynamicEndpoints
================

[](#dynamicendpoints)

A super-simple PHP library for creating nice APIs. It allows you to have urls like api.foo.com/my/endpoint/2

The Idea
--------

[](#the-idea)

When writing an HTTP API in PHP it is much nicer to have a url like this: `api.foo.com/books/2` instead of this `api.foo.com/books.php?id=2`. This is simple enough to do, use a custom apache 404 page, then parse the URL, but that can be a pain. So I made a tiny library for it.

Usage
-----

[](#usage)

For a working example, see the test directory. ###.htaccess In the root folder you have to have a `.htaccess` file that defines a main page, perhaps `index.php` as the 404 ErrorDoucument. It could look like this:

```
ErrorDocument 404 /dynamic-endpoints/test/index.php

```

### PHP

[](#php)

First, import the sources:

```
require_once(__DIR__ . "/../src/DynamicEndpoint.php");
```

or use composer and just require your `autoload.php`:

```
composer require vogon101/dynamic-endpoints
```

Next, create an API object. `$base` is the path that you want all the APIs to come off of. For example for something like this: `http://foo.com/my-thing/api/` the `$base` would be `/my-thing/api`. Base can be blank, for something at the root url.

```
$base = "/dynamic-endpoints/test";
$API = new BluePost\API($base);
```

Now, you have to register the endpoints. These define what URLs can be accessed through the API. The keys are the endpoint strings and the values are the files to be run if the endpoint is accessed. They can contain named variables and wildcards:

```
//Register the endpoints
//Variables are defined with %varName
//A .. is a wildcard
$API->register(Array(
    "/api/movie/../%name/%prop/.." => __DIR__ . "/movie.php",
    "/api/movie/" => __DIR__ . "/movie2.php",
    "/api/book/%id" => __DIR__ . "/book.php",
    "/api/book/name/%name" => __DIR__ . "/book2.php"
));
```

So `/api/book/%id` will match this `/api/book/2` and it will pass `$id` with value 2. However because `/api/book/name/%name` is very similar to the `%id` one, if a user were to navigate to `/api/book/name/` then the algorithm will match it to the `%id` endpoint, loading it with `$id = "name"`

Now we simply run the API. This will include the file specified if the enpoint matches. The variables will be set as specified in the scope of the file. If no endpoint is found, and array will be returned with an key of `"Error"`.

```
//Look for an endpoint, will run the file if one is found
$result = $API->runEndpoint();
if (array_key_exists("error", $result)) var_dump ($result);
```

License
-------

[](#license)

The software is avaliable under the Creative Commons Attribution 4.0 International. It can be found here:

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3677d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5211a845aac8e0293f5755add78b27f783893bac9c50016590a4feeb57abb472?d=identicon)[vogon101](/maintainers/vogon101)

---

Top Contributors

[![vogon101](https://avatars.githubusercontent.com/u/6450697?v=4)](https://github.com/vogon101 "vogon101 (14 commits)")[![Jbithell](https://avatars.githubusercontent.com/u/8408967?v=4)](https://github.com/Jbithell "Jbithell (1 commits)")

---

Tags

apiajaxbluepost

### Embed Badge

![Health badge](/badges/vogon101-dynamic-endpoints/health.svg)

```
[![Health](https://phpackages.com/badges/vogon101-dynamic-endpoints/health.svg)](https://phpackages.com/packages/vogon101-dynamic-endpoints)
```

###  Alternatives

[pubnub/pubnub

This is the official PubNub PHP SDK repository.

1314.6M17](/packages/pubnub-pubnub)[agungsugiarto/codeigniter4-cors

Send CORS Headers in a CodeIgniter 4 application.

6524.6k2](/packages/agungsugiarto-codeigniter4-cors)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
