This is a simple RESTful API for a blog post system using Laravel. It provides CRUD operations for blog posts. The API uses Laravel Sanctum for authentication.
- PHP 8.1+
- Composer
- MySQL/MariaDB or any other database supported by Laravel
-
Clone the repository:
git clone https://github.com/rodinmehr/3_sided_cube_api.git cd 3_sided_cube_api
-
Install dependencies:
composer install
-
Copy the
.env.example
file to.env
and configure the database settings:cp .env.example .env
-
Generate an application key:
php artisan key:generate
-
Run migrations:
php artisan migrate
-
Seed the database with sample data:
php artisan db:seed
-
Generate OpenAPI (Swagger) documentation:
php artisan l5-swagger:generate
-
Run Queue for handling jobs:
php artisan queue:work
To start the development server, run:
php artisan serve
The API will be available at http://localhost:8000/api
.
- POST
/api/login
: Log in and receive an access token - POST
/api/logout
: Log out (requires authentication) - GET
/api/posts
: Show all posts (Public) - POST
/api/posts
: Create a new post (Requires Authentication) - GET
/api/posts/{id}
: Show a specific post (Public) - PUT
/api/posts/{id}
: Update a specific post (Requires Authentication) - DELETE
/api/posts/{id}
: Delete a specific post (Requires Authentication)
You can use Postman collection that is provided in 3_sided_cube_api.postman_collection.json
file to test the endpoints.
API documentation is available here: http://localhost:8000/api/documentation
where detailed information about the API endpoints is displayed.
This API uses Laravel Sanctum for authentication. To authenticate:
- Make a POST request to
/api/login
with the email and password to receive an access token. - Include the access token in the
Authorization
header of the requests:
Authorization: Bearer {received_access_token}
Default user:
email: [email protected]
password: cubetest
To run the tests, it's better to set up a new database to preserve the original one. Copy the .env.example
file to .env.testing
and configure the test database settings:
cp .env.example .env.testing
Run migrations:
php artisan migrate --env=testing
To run the feature tests, use the following command:
php artisan test --env=testing
This open-source project is licensed under the MIT License - see the LICENSE file for details.