{"id":15746149,"url":"https://github.com/alesanchezr/slim-api-wrapper","last_synced_at":"2025-07-24T22:34:41.725Z","repository":{"id":56944147,"uuid":"180408196","full_name":"alesanchezr/slim-api-wrapper","owner":"alesanchezr","description":"A Small Upgrade to Slimp PHP to avoid having to do the same code again and again","archived":false,"fork":false,"pushed_at":"2019-05-09T01:33:27.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T06:15:31.643Z","etag":null,"topics":["php-api","slim-framework","slim-php","slim3"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alesanchezr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-09T16:29:43.000Z","updated_at":"2019-05-09T01:33:09.000Z","dependencies_parsed_at":"2022-08-21T07:50:48.327Z","dependency_job_id":null,"html_url":"https://github.com/alesanchezr/slim-api-wrapper","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/alesanchezr/slim-api-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alesanchezr%2Fslim-api-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alesanchezr%2Fslim-api-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alesanchezr%2Fslim-api-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alesanchezr%2Fslim-api-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alesanchezr","download_url":"https://codeload.github.com/alesanchezr/slim-api-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alesanchezr%2Fslim-api-wrapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266913680,"owners_count":24005579,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["php-api","slim-framework","slim-php","slim3"],"created_at":"2024-10-04T04:41:32.807Z","updated_at":"2025-07-24T22:34:41.667Z","avatar_url":"https://github.com/alesanchezr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slim On Steroids\n\n[![Build Status](https://travis-ci.org/alesanchezr/slim-api-wrapper.svg?branch=master)](https://travis-ci.org/alesanchezr/json-orm)\n[![Coverage Status](https://coveralls.io/repos/github/alesanchezr/slim-api-wrapper/badge.svg?branch=master)](https://coveralls.io/github/alesanchezr/slim-api-wrapper?branch=master)\n\nJust a small slim wrapper to avoid doing the same things all over again every time I start a new API.\n\nThis package is ideal for doing micro-framework architectures where your api is distributed thru several independet servers/developments.\n\n## Instalation\n\n```bash\n$ composer require alesanchezr/slim-api-wrapper\n```\n\nIf you are going to use Authorization headers you have to allow apache to use HTTP Headers in your `.htaccess`:\n```\nRewriteEngine On\nRewriteCond %{HTTP:Authorization} ^(.*)\nRewriteRule .* - [e=HTTP_AUTHORIZATION:%1]\n```\n\n## Creating an API in 1 minute 🧐\n\nHere is an example on how to create a simple api with just one `GET /hello` endpoint\n\n```php\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nrequire(\"./vendor/autoload.php\");\n\n$api = new \\SlimAPI\\SlimAPI([\n\t'name' =\u003e 'My Super Duper API',\n\t'debug' =\u003e true\n]);\n\n$api-\u003eget('/hello', function (Request $request, Response $response, array $args) use ($api) {\n\treturn $response-\u003ewithJson([\"Hello World\"]);\n});\n```\n\n## 📝 Adding a readme to the API\n\nIt is good practice to add a README.md file written in markwdown, just call the `$api-\u003eaddReadme()` method to specify the URI you will want users to access yout `README.md`\n```\n// here users will GET to path /readme in order to read the readme\n$api-\u003eaddReadme('/readme');\n\n//here users will GET to the root to read the readme file, but you can also specify the name of your readme file.\n$api-\u003eaddReadme('/','./INSTRUCTIONS.md');\n```\n\n## 💻 Adding more endpoints\n\nThe API uses [Slim PHP 3.0](http://www.slimframework.com/) on the background, you can add as many endpoints as you like following the [Slim documetation](http://www.slimframework.com/docs/).\n\n💡 Here is a [list of examples you can use](https://github.com/alesanchezr/slim-api-wrapper/tree/master/example).\n\n## 🔑 JWT Authentication\n\n1. To create private/authenticated the endpoints just add `-\u003eadd($inst-\u003eauth());` at the end of the edpoint like this:\n\n```php\n\n    $inst-\u003eapp-\u003eget('/hello/private', function (Request $request, Response $response, array $args){\n        \n        return $response-\u003ewithJson([\n            \"private\" =\u003e \"object\"\n        ]);\n\t    \n    })-\u003eadd($inst-\u003eauth()); //here I say I want this endpoint to be private\n\n```\n\n2. Add a secret seed to the API, this will be used as salt for the token generation and you only have to do this step once.\n\n```php\n// adding an internal seed for random private key generation\n// this only has to be done once in the entire API\n$api-\u003esetJWTKey(\"adSAD43gtterT%rtwre32@\");\n```\n\n3. Add at least one client to the API, you can pick a username but the secret key has to be generated using the `generatePrivateKey` method.\n```php\n// pick any username you like for the JWT credentials\n$clientId = \"alesanchezr\";\n\n// generate a key based on that username\n$clientKey = $api-\u003egeneratePrivateKey($clientId);\n```\n\n4. Now you can make call any request but you have to add the key to the Request `Authorization` header or as `access_token` on the querystring:\n\n### Using QueriString for authentication\n\n```js\n//here is an example in Javascript using QueryString autentication\nfetch('https://my_api.com/path/to/endpoint?access_token=ddsfs#@$fsd3425Ds')\n    .then(resp =\u003e {\n        //if the token is wrong you will recive status == 403\n        if(resp.status == 403) console.error(\"You have a wrong access_token token\");\n        else if(resp.ok) return resp.json()\n        else console.error(\"Uknown problem on the API\");\n    })\n    .then(data =\u003e console.log(data))\n    .catch(err =\u003e console.error(\"There is a problem on the front-end or the API is down\"))\n```\n\n### Using `Authorization` header for authentication\n\n```js\n//here is an example in Javascript using QueryString autentication\nfetch('https://my_api.com/path/to/endpoint', {\n    'method': 'POST',\n    'headers': {\n        'Content-Type': ''\n        'Authorization': 'JWT asdA@SDad!sdASASDsd453453SDF43'\n    },\n    'body': JSON.stringify(data)\n})\n    .then(resp =\u003e {\n        //if the token is wrong you will recive status == 403\n        if(resp.status == 403) console.error(\"You have a wrong access_token token\");\n        else if(resp.ok) return resp.json()\n        else console.error(\"Uknown problem on the API\");\n    })\n    .then(data =\u003e console.log(data))\n    .catch(err =\u003e console.error(\"There is a problem on the front-end or the API is down\"))\n```\n\n## Aditional Info\n\nRun the tests:\n```sh\n./vendor/bin/phpunit example/with_tests/tests.php --colors\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falesanchezr%2Fslim-api-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falesanchezr%2Fslim-api-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falesanchezr%2Fslim-api-wrapper/lists"}