Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-11-25 (5 days ago) | Not enough user ratings | Total: 10 This week: 10 | All time: 11,457 This week: 6 |
Version | License | PHP version | Categories | |||
luminova-rest-api-ex 3.0 | MIT/X Consortium ... | 8.0 | Libraries, Web services, Design Patterns, P..., A... |
Description | Author | |
This package implements an example of a REST API. |
<?php |
This repository provides a comprehensive example of building a RESTful API using the Luminova PHP framework, showcasing both HTTP and CLI implementations. The example is designed to help developers understand how to create APIs that support full CRUD operations (Create, Read, Update, Delete) and handle various HTTP methods such as GET
, POST
, PUT
, and DELETE
. It also supports secure content delivery through the Luminova\Storages\FileDelivery
class. This feature enables serving images stored in private directories directly via URL access, eliminating the need for creating symbolic links (symlinks
).
In addition to HTTP-based API endpoints, this example also demonstrates the power of Luminova's command-line tools, making it possible to perform API-related tasks directly via the CLI. Whether you're looking to seed your database, manage user tokens, or perform backend operations, this repository covers it all.
By following the provided steps, you can quickly set up an API infrastructure, learn best practices for working with Luminova, and explore features like database migrations, API client authentication, and middleware for rate-limiting or token validation.
This project is ideal for developers aiming to: - Build scalable and secure APIs for web and mobile applications. - Explore the seamless integration of HTTP and CLI workflows. - Learn Luminova's approach to rapid API development and management.
Below is an overview of the primary files involved in the API implementation, organized by functionality and purpose. Each file plays a critical role in building a RESTful API using the Luminova PHP framework.
Controllers handle HTTP and CLI requests, providing routes and business logic for the API.
Define the database schema for the API's core entities.
- App\Database\Migrations\PostsMigration
Defines the schema for the posts
table, including fields for title
, body
, and relationships with users.
Populate the database with initial data. - App\Database\Seeders\PostsSeeder Inserts sample post data for testing and development purposes.
Models provide a programmatic interface for interacting with the database tables.
- App\Models\Posts
Represents the posts
table, including relationships to users and validation logic for creating or updating posts.
Clone the repository using Git or download the files directly from GitHub:
cd your-project-path
git clone https://github.com/luminovang/luminova-rest-api-example.git
Navigate to the project directory and update the Composer dependencies:
composer update
Configure your MySQL socket path in the .env
file:
database.mysql.socket.path = /var/mysql/mysql.sock
Use the Luminova built-in development server or a third-party server such as XAMPP
or WAMPP
.
Apply database migrations to create the required tables:
php novakit db:migrate
Populate the database with sample data:
php novakit db:seed
Generate an API token for your client:
Example:
cd public
php index.php posts key --user-id=1 --quota=1000 --expiry=3600
Copy the generated API token for use with API tools like Postman
or curl
.
GET
Retrieve all post contents.
curl --location 'https://localhost/your-project-path/public/api/v1/posts' \
--header 'X-Api-Client-Id: <your-client-id>' \
--header 'Authorization: <your-api-token>'
For more examples and details, refer to the documentation in this repository.
GET
Retrieve a single post content by id.
curl --location 'https://localhost/your-project-path/public/api/v1/posts/<post-id>' \
--header 'X-Api-Client-Id: <your-client-id>' \
--header 'Authorization: <your-api-token>'
POST
Create a new post with an optional image.
curl --location 'https://localhost/your-project-path/public/api/v1/posts/create' \
--header 'X-Api-Client-Id: <your-client-id>' \
--header 'Authorization: <your-api-token>' \
--form 'body="{
\"userId\": 10,
\"title\": \"This a test new title\",
\"body\": \"New Body content\"
}"' \
--form 'image=@"/Path/To/Images/image.png"'
PUT
Update a existing post with an optional image.
curl --location --request PUT 'https://localhost/your-project-path/public/api/v1/posts/update/<post-id>' \
--header 'X-Api-Client-Id: <your-client-id>' \
--header 'Authorization: <your-api-token>' \
--form 'body="{
\"title\": \"New Update a test new title\",
\"body\": \"New Update Body content\"
}"'
PUT
Delete a existing post.
curl --location --request DELETE 'https://localhost/your-project-path/public/api/v1/posts/delete/<post-id>' \
--header 'X-Api-Client-Id: <your-client-id>' \
--header 'Authorization: <your-api-token>'
First navigate to public
directory of your project.
Lists users with optional pagination.
php index.php posts users --limit=10 --offset=0
Lists posts with optional pagination.
php index.php posts list --limit=2
For more, run help command to show all available post commands:
php index.php posts --help
Files (119) |
File | Role | Description | ||
---|---|---|---|---|
app (1 file, 6 directories) | ||||
bootstrap (3 files) | ||||
public (3 files, 1 directory) | ||||
resources (1 directory) | ||||
routes (3 files) | ||||
samples (1 directory) | ||||
system (1 file, 3 directories) | ||||
composer.json | Data | Auxiliary data | ||
index.php | Aux. | Configuration script | ||
LICENSE | Lic. | License text | ||
novakit | Example | Example script | ||
phpstan.includes.php | Aux. | Configuration script | ||
phpstan.neon | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
rector.php | Class | Class source |
Files (119) | / | app |
File | Role | Description | ||
---|---|---|---|---|
Config (20 files, 1 directory) | ||||
Controllers (3 directories) | ||||
Database (2 directories) | ||||
Languages (2 files) | ||||
Models (2 files) | ||||
Utils (2 files) | ||||
Application.php | Class | Class source |
Files (119) | / | app | / | Config |
File | Role | Description | ||
---|---|---|---|---|
Templates (2 directories) | ||||
AI.php | Class | Class source | ||
Apis.php | Class | Class source | ||
Browser.php | Class | Class source | ||
ContentSecurityPolicy.php | Class | Class source | ||
Cookie.php | Class | Class source | ||
Cron.php | Class | Class source | ||
Database.php | Class | Class source | ||
Encryption.php | Class | Class source | ||
Files.php | Class | Class source | ||
IPConfig.php | Class | Class source | ||
Logger.php | Class | Class source | ||
Mailer.php | Class | Class source | ||
Modules.php | Aux. | Configuration script | ||
Schema.php | Aux. | Configuration script | ||
Security.php | Class | Class source | ||
Services.php | Class | Class source | ||
Session.php | Class | Class source | ||
Sitemap.php | Class | Class source | ||
Storage.php | Aux. | Configuration script | ||
Template.php | Class | Class source |
Files (119) | / | app | / | Config | / | Templates | / | Smarty |
File | Role | Description |
---|---|---|
Classes.php | Class | Class source |
Modifiers.php | Class | Class source |
Files (119) | / | app | / | Config | / | Templates | / | Twig |
File | Role | Description |
---|---|---|
Extensions.php | Class | Class source |
Filters.php | Class | Class source |
Functions.php | Class | Class source |
Globals.php | Class | Class source |
NodeVisitors.php | Class | Class source |
Operators.php | Class | Class source |
Rot13Provider.php | Class | Class source |
Tests.php | Class | Class source |
TokenParsers.php | Class | Class source |
Files (119) | / | app | / | Controllers | / | Http |
File | Role | Description |
---|---|---|
RestController.php | Class | Class source |
Welcome.php | Class | Class source |
Files (119) | / | app | / | Database | / | Migrations |
File | Role | Description |
---|---|---|
PostsMigration.php | Class | Class source |
UserMigration.php | Class | Class source |
Files (119) | / | app | / | Database | / | Seeders |
File | Role | Description |
---|---|---|
PostsSeeder.php | Class | Class source |
UserSeeder.php | Class | Class source |
Files (119) | / | app | / | Languages |
File | Role | Description |
---|---|---|
App.en.php | Aux. | Configuration script |
App.fr.php | Aux. | Configuration script |
Files (119) | / | app | / | Models |
Files (119) | / | app | / | Utils |
File | Role | Description |
---|---|---|
Functions.php | Class | Class source |
Global.php | Aux. | Configuration script |
Files (119) | / | bootstrap |
File | Role | Description |
---|---|---|
constants.php | Example | Example script |
features.php | Aux. | Configuration script |
functions.php | Class | Class source |
Files (119) | / | public |
File | Role | Description | ||
---|---|---|---|---|
assets (1 directory) | ||||
favicon.png | Icon | Icon image | ||
index.php | Example | Example script | ||
robots.txt | Data | Robots blocking configuration |
Files (119) | / | resources | / | Views |
File | Role | Description | ||
---|---|---|---|---|
system_errors (13 files) | ||||
404.php | Example | Example script | ||
index.php | Aux. | Configuration script | ||
index.tpl | Data | Auxiliary data | ||
index.twig | Data | Auxiliary data |
Files (119) | / | resources | / | Views | / | system_errors |
File | Role | Description |
---|---|---|
404.php | Aux. | Configuration script |
api.php | Example | Example script |
cli.php | Class | Class source |
debug.css | Data | Auxiliary data |
errors.php | Example | Example script |
info.php | Aux. | Configuration script |
mailer.php | Example | Example script |
maintenance.css | Data | Auxiliary data |
maintenance.php | Aux. | Configuration script |
remote.php | Example | Example script |
tracer.php | Example | Example script |
tracing.php | Example | Example script |
view.error.php | Class | Class source |
Files (119) | / | routes |
Files (119) | / | samples | / | app | / | Config |
File | Role | Description |
---|---|---|
Cron.php | Class | Class source |
Files.php | Class | Class source |
Logger.php | Class | Class source |
Mailer.php | Class | Class source |
Files (119) | / | system |
Files (119) | / | system | / | Composer |
File | Role | Description |
---|---|---|
BaseComposer.php | Class | Class source |
Builder.php | Class | Class source |
Updater.php | Class | Class source |
Files (119) | / | system | / | Debugger |
File | Role | Description |
---|---|---|
Performance.php | Class | Class source |
PHPStanRules.php | Class | Class source |
Tracer.php | Class | Class source |
Files (119) | / | system | / | plugins |
File | Role | Description | ||
---|---|---|---|---|
composer (11 files) | ||||
psr (1 directory) | ||||
autoload.php | Aux. | Configuration script |
Files (119) | / | system | / | plugins | / | composer |
File | Role | Description |
---|---|---|
autoload_classmap.php | Aux. | Configuration script |
autoload_namespaces.php | Aux. | Configuration script |
autoload_psr4.php | Aux. | Configuration script |
autoload_real.php | Class | Class source |
autoload_static.php | Class | Class source |
ClassLoader.php | Class | Class source |
installed.json | Data | Auxiliary data |
installed.php | Aux. | Configuration script |
InstalledVersions.php | Class | Class source |
LICENSE | Lic. | License text |
platform_check.php | Aux. | Configuration script |
Files (119) | / | system | / | plugins | / | psr | / | log |
File | Role | Description | ||
---|---|---|---|---|
Psr (1 directory) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Class | Class source |
Files (119) | / | system | / | plugins | / | psr | / | log | / | Psr | / | Log |
File | Role | Description | ||
---|---|---|---|---|
Test (3 files) | ||||
AbstractLogger.php | Class | Class source | ||
InvalidArgumentException.php | Class | Class source | ||
LoggerAwareInterface.php | Class | Class source | ||
LoggerAwareTrait.php | Class | Class source | ||
LoggerInterface.php | Class | Class source | ||
LoggerTrait.php | Class | Class source | ||
LogLevel.php | Class | Class source | ||
NullLogger.php | Class | Class source |
Files (119) | / | system | / | plugins | / | psr | / | log | / | Psr | / | Log | / | Test |
File | Role | Description |
---|---|---|
DummyTest.php | Class | Class source |
LoggerInterfaceTest.php | Class | Class source |
TestLogger.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
luminova-rest-api-ex-2024-11-25.zip 163KB | |
luminova-rest-api-ex-2024-11-25.tar.gz 105KB | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.