|
1 |
| -<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p> |
| 1 | +# Todo task |
2 | 2 |
|
3 |
| -<p align="center"> |
4 |
| -<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a> |
5 |
| -<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a> |
6 |
| -<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a> |
7 |
| -<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a> |
8 |
| -</p> |
| 3 | +Example RESTFUll API in Laravel |
| 4 | +## Overview |
9 | 5 |
|
10 |
| -## About Laravel |
| 6 | +This repository serves as a comprehensive example of a meticulously crafted RESTful API using Laravel. It not only showcases the implementation of RESTful endpoints but also embodies best practices in coding, leveraging Laravel's robust features. |
11 | 7 |
|
12 |
| -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: |
| 8 | +### Features Showcased: |
13 | 9 |
|
14 |
| -- [Simple, fast routing engine](https://laravel.com/docs/routing). |
15 |
| -- [Powerful dependency injection container](https://laravel.com/docs/container). |
16 |
| -- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. |
17 |
| -- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). |
18 |
| -- Database agnostic [schema migrations](https://laravel.com/docs/migrations). |
19 |
| -- [Robust background job processing](https://laravel.com/docs/queues). |
20 |
| -- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). |
| 10 | +- **Implementation of RESTful API Endpoints:** Demonstrates a well-defined structure and functionality of various API endpoints adhering to RESTful principles. |
| 11 | +- **Leveraging Laravel's Response and Request Handling:** Utilizes Laravel's built-in functionalities effectively for handling responses, managing requests, and ensuring secure data flow. |
| 12 | +- **Exemplary Demonstration of Clean and Structured Code:** Emphasizes clean, maintainable, and structured coding practices, serving as a guide for developers to create organized and scalable applications. |
21 | 13 |
|
22 |
| -Laravel is accessible, powerful, and provides tools required for large, robust applications. |
| 14 | +This example repository offers an insightful reference for implementing RESTful APIs in Laravel. Dive into the codebase to gain a deeper understanding of utilizing Laravel's features effectively and implementing industry-best practices. |
23 | 15 |
|
24 |
| -## Learning Laravel |
| 16 | +### Purpose |
25 | 17 |
|
26 |
| -Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. |
| 18 | +Primarily, this source code repository serves as an educational resource, exemplifying how to architect and structure a robust RESTful API project using Laravel. It aims to aid developers in comprehending the implementation of Laravel features and adopting optimal coding practices for their projects. |
27 | 19 |
|
28 |
| -If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. |
| 20 | +Feel free to explore, learn, and adapt the showcased patterns and practices to enhance your own projects. |
29 | 21 |
|
30 |
| -## Laravel Sponsors |
| 22 | +## Installation |
31 | 23 |
|
32 |
| -We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). |
| 24 | +### Prerequisites |
33 | 25 |
|
34 |
| -### Premium Partners |
| 26 | +- PHP ^7.3 | ^8.0 |
| 27 | +- laravel 8 |
35 | 28 |
|
36 |
| -- **[Vehikl](https://vehikl.com/)** |
37 |
| -- **[Tighten Co.](https://tighten.co)** |
38 |
| -- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** |
39 |
| -- **[64 Robots](https://64robots.com)** |
40 |
| -- **[Cubet Techno Labs](https://cubettech.com)** |
41 |
| -- **[Cyber-Duck](https://cyber-duck.co.uk)** |
42 |
| -- **[Many](https://www.many.co.uk)** |
43 |
| -- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** |
44 |
| -- **[DevSquad](https://devsquad.com)** |
45 |
| -- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** |
46 |
| -- **[OP.GG](https://op.gg)** |
47 |
| -- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)** |
48 |
| -- **[Lendio](https://lendio.com)** |
| 29 | +### Steps |
49 | 30 |
|
50 |
| -## Contributing |
| 31 | +1. Clone the repository: |
| 32 | + ```bash |
| 33 | + git clone https://github.com/amirsahra/todo-task-api.git |
| 34 | + ``` |
| 35 | +2. Install dependencies: |
| 36 | + ```bash |
| 37 | + composer install |
| 38 | + ``` |
| 39 | +3. Set up environment variables by creating a `.env` file: |
| 40 | + ```bash |
| 41 | + cp .env.example .env |
| 42 | + ``` |
| 43 | + Update `.env` with your configuration (database, app key, etc.). |
| 44 | + |
| 45 | +4. Run migrations and seeders (if applicable): |
| 46 | + ```bash |
| 47 | + php artisan migrate --seed |
| 48 | + ``` |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +Explain how to use your API: |
| 53 | + |
| 54 | +1. Start the development server: |
| 55 | + ```bash |
| 56 | + php artisan serve |
| 57 | + ``` |
| 58 | + |
| 59 | +2. Use tools like Postman or curl to interact with the API endpoints. |
| 60 | + |
| 61 | +## API Endpoints |
| 62 | + |
| 63 | +### List of Available Endpoints |
| 64 | + |
| 65 | +#### Auth Endpoints |
| 66 | + |
| 67 | +- **Login** |
| 68 | + - Method: `POST` |
| 69 | + - Description: Logs in a user with their credentials. |
| 70 | + - Example: |
| 71 | + ```bash |
| 72 | + POST http://127.0.0.1:8000/api/V1/login |
| 73 | +
|
| 74 | + Body: |
| 75 | + { |
| 76 | + "email": "vhammes@example.com", |
| 77 | + "password": "123456789" |
| 78 | + } |
| 79 | + ``` |
| 80 | + |
| 81 | +- **Logout** |
| 82 | + - Method: `POST` |
| 83 | + - Description: Logs out the currently logged-in user. |
| 84 | + - Example: |
| 85 | + ```bash |
| 86 | + POST http://127.0.0.1:8000/api/V1/logout |
| 87 | +
|
| 88 | + Body: |
| 89 | + { |
| 90 | + "email": "vhammes@example.com", |
| 91 | + "password": "123456789" |
| 92 | + } |
| 93 | + ``` |
| 94 | + |
| 95 | +- **Register** |
| 96 | + - Method: `POST` |
| 97 | + - Description: Registers a new user. |
| 98 | + - Example: |
| 99 | + ```bash |
| 100 | + POST http://127.0.0.1:8000/api/V1/register |
| 101 | +
|
| 102 | + Body: |
| 103 | + { |
| 104 | + "name": "amir", |
| 105 | + "email": "amirhosein.sahra@gmail.com", |
| 106 | + "password": "123456789" |
| 107 | + } |
| 108 | + ``` |
| 109 | + |
| 110 | +- **Show Current User** |
| 111 | + - Method: `GET` |
| 112 | + - Description: Retrieves information about the currently logged-in user. |
| 113 | + - Example: |
| 114 | + ```sql |
| 115 | + GET http://127.0.0.1:8000/api/user |
| 116 | +
|
| 117 | + Headers: |
| 118 | + { |
| 119 | + "Authorization": "Bearer 1|pY6W2ys7VWlTgaSr4pAbc0XOVIRWcbdNihqaWCMU", |
| 120 | + "Accept": "application/json", |
| 121 | + "Referer": "localhost" |
| 122 | + } |
| 123 | + ``` |
| 124 | + |
| 125 | +#### Task Endpoints |
51 | 126 |
|
52 |
| -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). |
| 127 | +- **Index** |
| 128 | + - Method: `GET` |
| 129 | + - Description: Retrieves all tasks. |
| 130 | + - Example: |
| 131 | + ```bash |
| 132 | + GET http://127.0.0.1:8000/api/V1/tasks |
53 | 133 |
|
54 |
| -## Code of Conduct |
| 134 | + Headers: |
| 135 | + { |
| 136 | + "Authorization": "Bearer 3|vJjX0aKJYOgcXodNqWqpWbImfE3MYUPxEwjPlMN2", |
| 137 | + "Accept": "application/json" |
| 138 | + } |
| 139 | + ``` |
55 | 140 |
|
56 |
| -In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). |
| 141 | +- **Show** |
| 142 | + - Method: `GET` |
| 143 | + - Description: Retrieves details of a specific task by ID. |
| 144 | + - Example: |
| 145 | + ```bash |
| 146 | + GET http://127.0.0.1:8000/api/V1/tasks/1 |
57 | 147 |
|
58 |
| -## Security Vulnerabilities |
| 148 | + Headers: |
| 149 | + { |
| 150 | + "Authorization": "Bearer 3|vJjX0aKJYOgcXodNqWqpWbImfE3MYUPxEwjPlMN2", |
| 151 | + "Accept": "application/json" |
| 152 | + } |
| 153 | + ``` |
| 154 | + |
| 155 | +- **Store** |
| 156 | + - Method: `POST` |
| 157 | + - Description: Creates a new task. |
| 158 | + - Example: |
| 159 | + ```css |
| 160 | + POST http://127.0.0.1:8000/api/V1/tasks |
| 161 | +
|
| 162 | + Headers: |
| 163 | + { |
| 164 | + "Authorization": "Bearer 3|vJjX0aKJYOgcXodNqWqpWbImfE3MYUPxEwjPlMN2", |
| 165 | + "Accept": "application/vnd.api+json" |
| 166 | + } |
| 167 | + Body: |
| 168 | + { |
| 169 | + "name": "amir hossein sahra" |
| 170 | + } |
| 171 | + ``` |
| 172 | + |
| 173 | +- **Update** |
| 174 | + - Method: `PUT` |
| 175 | + - Description: Updates an existing task by ID. |
| 176 | + - Example: |
| 177 | + ```css |
| 178 | + PUT http://127.0.0.1:8000/api/V1/tasks/13 |
| 179 | +
|
| 180 | + Headers: |
| 181 | + { |
| 182 | + "Authorization": "Bearer 3|vJjX0aKJYOgcXodNqWqpWbImfE3MYUPxEwjPlMN2", |
| 183 | + "Accept": "application/json" |
| 184 | + } |
| 185 | + Body: |
| 186 | + { |
| 187 | + "name": "new name update" |
| 188 | + } |
| 189 | + ``` |
| 190 | + |
| 191 | +- **Completed** |
| 192 | + - Method: `PATCH` |
| 193 | + - Description: Marks a task as completed by ID. |
| 194 | + - Example: |
| 195 | + ```bash |
| 196 | + PATCH http://127.0.0.1:8000/api/V1/tasks/10/complete |
| 197 | +
|
| 198 | + Headers: |
| 199 | + { |
| 200 | + "Authorization": "Bearer 1|pY6W2ys7VWlTgaSr4pAbc0XOVIRWcbdNihqaWCMU", |
| 201 | + "Accept": "application/json" |
| 202 | + } |
| 203 | + ``` |
| 204 | + |
| 205 | +- **Destroy** |
| 206 | + - Method: `DELETE` |
| 207 | + - Description: Deletes a task by ID. |
| 208 | + - Example: |
| 209 | + ```bash |
| 210 | + DELETE http://127.0.0.1:8000/api/V1/tasks/11 |
| 211 | +
|
| 212 | + Headers: |
| 213 | + { |
| 214 | + "Authorization": "Bearer 3|vJjX0aKJYOgcXodNqWqpWbImfE3MYUPxEwjPlMN2" |
| 215 | + } |
| 216 | + ``` |
| 217 | + |
| 218 | +## Authentication |
| 219 | +### Token-Based Authentication |
| 220 | + |
| 221 | +This API utilizes Token-Based Authentication, specifically using the Bearer Token for authentication. In this method, a token serves as the authentication credential for each request sent. |
| 222 | + |
| 223 | +#### Examples of Authentication |
| 224 | + |
| 225 | +##### Login Endpoint |
| 226 | + |
| 227 | +To log in, a POST request is used at this address: |
| 228 | + |
| 229 | +```http |
| 230 | +POST http://127.0.0.1:8000/api/V1/login |
| 231 | +
|
| 232 | +Body: |
| 233 | +{ |
| 234 | + "email": "vhammes@example.com", |
| 235 | + "password": "123456789" |
| 236 | +} |
| 237 | +``` |
| 238 | +This successful request provides the user with a token of type Bearer, |
| 239 | +which should be included in the headers of all subsequent requests: |
| 240 | +```http |
| 241 | +Authorization: Bearer YOUR_ACCESS_TOKEN |
| 242 | +``` |
| 243 | +#### Authentication Example in Endpoints |
| 244 | +For instance, in the headers of the following request, |
| 245 | +the token used for authentication is sent as a Bearer in the request: |
| 246 | +```http |
| 247 | +GET http://127.0.0.1:8000/api/user |
| 248 | +
|
| 249 | +Headers: |
| 250 | +{ |
| 251 | + "Authorization": "Bearer YOUR_ACCESS_TOKEN", |
| 252 | + "Accept": "application/json", |
| 253 | + "Referer": "localhost" |
| 254 | +} |
| 255 | +``` |
| 256 | + |
| 257 | +## Contributing |
59 | 258 |
|
60 |
| -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. |
| 259 | +Explain how other developers can contribute to the project. Include information about submitting issues, pull requests, coding standards, etc. |
61 | 260 |
|
62 | 261 | ## License
|
63 | 262 |
|
64 |
| -The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
| 263 | +Specify the license for your project. |
0 commit comments