https://github.com/cttricks/xpress
Express.js inspired PHP library to simplify your API development.
https://github.com/cttricks/xpress
api-wrapper application express php php-library php-router router webapp
Last synced: 16 days ago
JSON representation
Express.js inspired PHP library to simplify your API development.
- Host: GitHub
- URL: https://github.com/cttricks/xpress
- Owner: cttricks
- License: apache-2.0
- Created: 2023-09-27T05:44:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-30T09:20:56.000Z (over 2 years ago)
- Last Synced: 2025-03-15T13:42:30.280Z (about 1 year ago)
- Topics: api-wrapper, application, express, php, php-library, php-router, router, webapp
- Language: PHP
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Xpress
Xpress is a versatile PHP library designed to streamline the creation of API endpoints, drawing inspiration from the simplicity and elegance of `Express.js`, a popular framework in the `Node.js` ecosystem. This library, currently in its beta stage, empowers developers to handle HTTP GET and POST requests with ease.
### Requirements
- PHP >= 5.1
### Installation
Currently you can simply download this repository and start using it. No additional configuration required.
### Routing
```php
send('Xpress is live! 🥳🥳');
});
APP::end();
```
### 1. Virtual prefix
```php
APP::get('/user/:id', function($req, $res){
$res->status(200)->json(array('userId'=> $req['id']));
});
```
### 2. Using external file
In order to use external file to route request and manage from another php file, you have to create a rout in `index.php` file. In this example it'll be in `data` dir i.e `data/vehicle.php`.
```php
status(200)->send('Hello! from vehicle.php file.');
});
/*Example 2 | With app defined status code | URL: http://localhost/vehicle/list*/
APP::get('/list', function($req, $res) use ($vehicleList){
$res->json($vehicleList);
});
/*Exmaple 3 | With virtual prefix | URL: http://localhost/vehicle/name/1*/
APP::get('/name/:index', function($req, $res) use ($vehicleList){
$res->send($vehicleList[$req['index']]);
});
APP::end();
```
### 3. Redirect
You can redirect a virtual path to any other endpoint, with status code & params. Here `true` is to include all params else you can pass an array of keys to be include in redirect URI.
```php
APP::redirect("/github", "https://github.com/cttricks", 302, true);
```
Or you can also include virtual prefix & use that as params in target URL
```php
APP::redirect("/github/:tab", "https://github.com/cttricks", 302, ['tab']);
```
Or keep it simeple & redirect without params
```php
APP::redirect("/github", "https://github.com/cttricks");
```
### Contribution
Contributions are welcome! If you think you can improve the performance, add more animations, or enhance the effects of xpress, I encourage you to contribute to the project.
To contribute, please follow these steps:
1. Fork the repository on GitHub.
2. Create a new branch with a descriptive name for your contribution.
3. Make your modifications, improvements, or additions to the codebase.
4. Test your changes to ensure they work as expected.
5. Commit your changes and push them to your forked repository.
6. Submit a pull request from your branch to the main repository's `master` branch.
I appreciate your contributions and will review your pull request as soon as possible. Feel free to provide any additional context, explanations, or documentation related to your contribution in the pull request description.
💡 Please note that by contributing to this repo, you agree to release your contributions under the Apache-2.0 License.
### License
Xpress is released under the Apache-2.0 License. See the LICENSE file for more details.
### Disclaimer
This project is a fun experiment and should not be used in a production environment without proper testing and security measures. Use it responsibly and at your own risk.
Feel free to reach out if you have any questions or encounter issues during setup. Happy coding!