{"id":15028497,"url":"https://github.com/willitscale/streetlamp","last_synced_at":"2025-04-09T20:30:36.213Z","repository":{"id":65537234,"uuid":"594251266","full_name":"willitscale/streetlamp","owner":"willitscale","description":"A HTTP router application wrapper.","archived":false,"fork":false,"pushed_at":"2024-11-25T21:57:51.000Z","size":171,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T22:24:28.387Z","etag":null,"topics":["composer","composer-package","data-mapper","hacktoberfest","http","php","php82","php83","router"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/willitscale/streetlamp","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willitscale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-28T00:39:38.000Z","updated_at":"2025-02-03T12:50:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"8684d9d2-6d9f-4a22-a3fe-2c7965717f74","html_url":"https://github.com/willitscale/streetlamp","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"1ee74a6f7b04318ba4c9907acda7772131736e7b"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fstreetlamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fstreetlamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fstreetlamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fstreetlamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willitscale","download_url":"https://codeload.github.com/willitscale/streetlamp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623010,"owners_count":20968574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","composer-package","data-mapper","hacktoberfest","http","php","php82","php83","router"],"created_at":"2024-09-24T20:08:28.527Z","updated_at":"2025-04-09T20:30:36.185Z","avatar_url":"https://github.com/willitscale.png","language":"PHP","readme":"# Streetlamp\n\n[![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/willitscale/streetlamp/php.yml)](https://github.com/willitscale/streetlamp/actions)\n[![Packagist License](https://img.shields.io/packagist/l/willitscale/streetlamp)](https://github.com/willitscale/streetlamp/blob/main/LICENSE)\n[![Packagist Version](https://img.shields.io/packagist/v/willitscale/streetlamp)](https://packagist.org/packages/willitscale/streetlamp)\n[![GitHub last commit](https://img.shields.io/github/last-commit/willitscale/streetlamp)](https://github.com/willitscale/streetlamp/commits/main)\n\n## Table of Contents\n- [1. Introduction](#1-introduction)\n- [2. Prerequisites](#2-prerequisites)\n- [3. Setup](#3-setup)\n\n## 1. Introduction\n\nStreetlamp is a simple routing library that allows you to quickly prototype APIs.\nThis library was built around the basic concepts of annotative routing, commonly found in Java libraries such as [JAX-RS](https://cxf.apache.org/docs/jax-rs.html) and [Spring](https://spring.io/).\nAlthough the way it works is inspired from the aforementioned Java libraries, it has a slightly unique implementation more fitting the PHP language.\n\n## 2. Prerequisites\n\nTo keep up with modern standards this library was built using PHP 8.2 and therefore will only run in said environment or greater. \nIf there is enough demand I may be willing to retrofit back to PHP 8, but as it's built with attributes it can't go back any further.\nFinally, this project requires composer and the [PSR-4 Autoload standard](https://www.php-fig.org/psr/psr-4/).\n\n## 3. Setup\n\n### 3.1. Installing the library\n\nSimply include Streetlamp in your project with the composer command:\n\n```sh\ncomposer require willitscale/streetlamp\n```\n\n### 3.2. Application Wrapper\n\nTo run your application through the Streetlamp wrapper all you need to do is instantiate the `Router` class and call `route`. \nThe `Router` will use a `RouteBuilder` to scan all of your namespaces in the `composer.json` (excluding test namespaces by default) and setup corresponding routes. \n\nHere's all the code you need to get going:\n\n```php\n\u003c?php declare(strict_types=1);\n\nrequire_once 'vendor/autoload.php';\n\nuse willitscale\\Streetlamp\\Router;\n\n(new Router())-\u003eroute();\n```\n\nThis will use a simple out of the box configuration, if you require any customisation this can be achieved with the `RouterConfig`.\nThere's a comprehensive guide on configuration in the [Configuration page](docs/CONFIGURATION.MD).\n\n### 3.3 Creating a Controller\n\nA controller can be defined by simply giving a class the attribute of `RouteController`.\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace Example;\n\nuse willitscale\\Streetlamp\\Attributes\\Controller\\RouteController;\n\n#[RouteController]\nclass MyRouteClass {\n}\n```\n\nOnly classes with the `RouteController` attribute will be scanned for routes.\n\n### 3.4. Creating a Route\n\nEach public method within a `RouteController` can be annotated as a route.\nThere's three requirements to transform a method into a route:\n- add a HTTP method attribute to the method,\n- a path attribute to the method or class and\n- return the `ResponseBuilder` object.\n\nLet's say we want to create a route for the request `GET /hello HTTP/1.1`, we would need to attribute our route method with the `Get` and `Path` attributes.\n\nHere's what that would look like in code:\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace Example;\n\nuse willitscale\\Streetlamp\\Attributes\\Controller\\RouteController;\nuse willitscale\\Streetlamp\\Attributes\\Path;\nuse willitscale\\Streetlamp\\Attributes\\Route\\Method;\nuse willitscale\\Streetlamp\\Builders\\ResponseBuilder;\nuse willitscale\\Streetlamp\\Enums\\HttpMethod;\nuse willitscale\\Streetlamp\\Enums\\HttpStatusCode;\n\n#[RouteController]\nclass MyRouteClass\n{\n    #[Path('/hello')]\n    #[Method(HttpMethod::GET)]\n    public function simpleGet(): ResponseBuilder\n    {\n        return (new ResponseBuilder())\n            -\u003esetData('world')\n            -\u003esetHttpStatusCode(HttpStatusCode::HTTP_OK);\n    }\n}\n```\n\nWe could have also applied the `#[Path('/hello')]` to the `RouteController` and then all routes defined within the controller have that path prefixed to them so you would not need to apply a path to them individually.\n\n## 4. Futher Reading\n- [Routing Attributes](docs/ROUTING_ATTRIBUTES.MD)\n- [Input Attributes](docs/INPUT_ATTRIBUTES.MD)\n- [Data Mapping](docs/DATA_MAPPING.MD)\n- [Validators](docs/VALIDATORS.MD)\n- [Caching](docs/CACHING.MD)\n- [Configuration](docs/CONFIGURATION.MD)\n- [Setup](docs/SETUP.MD)\n- [Testing](docs/TESTING.MD)\n- [Error Codes](docs/ERROR_CODES.MD)\n- [Commands](docs/COMMANDS.MD)\n- [Performance](docs/PERFORMANCE.MD)\n- [TODO](docs/TODO.MD)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillitscale%2Fstreetlamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillitscale%2Fstreetlamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillitscale%2Fstreetlamp/lists"}