1
- ## Blog Backend API
1
+ ## Laravel - Inertia - React
2
2
3
3
A Laravel-based RESTful API for managing blog posts and categories.
4
4
@@ -68,16 +68,18 @@ php artisan migrate:fresh --seed
68
68
php artisan serve
69
69
```
70
70
71
- 1 . Open the application in your web browser at ` http://localhost:8000 ` .
71
+ 9 . Open the application in your web browser at ` http://localhost:8000 ` .
72
72
73
73
## API Documentation
74
74
75
75
### Authentication
76
76
77
+ All authentication endpoints are prefixed with ` /api/auth ` .
78
+
77
79
#### Register
78
80
79
81
``` http
80
- POST /api/register
82
+ POST /api/auth/ register
81
83
```
82
84
83
85
| Parameter | Type | Description |
@@ -89,14 +91,24 @@ POST /api/register
89
91
#### Login
90
92
91
93
``` http
92
- POST /api/login
94
+ POST /api/auth/ login
93
95
```
94
96
95
97
| Parameter | Type | Description |
96
98
| :--- | :--- | :--- |
97
99
| ` email ` | ` string ` | ** Required** . User's email |
98
100
| ` password ` | ` string ` | ** Required** . User's password |
99
101
102
+ Successful login returns a ** Bearer** token that should be used for authenticated requests.
103
+
104
+ #### Logout
105
+
106
+ ``` http
107
+ POST /api/auth/logout
108
+ ```
109
+
110
+ Requires authentication. Invalidates the current access token.
111
+
100
112
### Posts
101
113
102
114
#### Get All Posts
@@ -105,10 +117,20 @@ POST /api/login
105
117
GET /api/posts
106
118
```
107
119
120
+ Supports filtering by:
121
+
122
+ ``` http
123
+ GET /api/posts?search=query&status=draft&is_featured=true&filter=trash&page=1&per_page=6
124
+ ```
125
+ - search query [ search=query]
126
+ - status [ status=draft/published]
127
+ - featured posts [ is_featured=true/false]
128
+ - trashed posts [ filter=all/trash/with_trashed]
129
+
108
130
#### Get Single Post
109
131
110
132
``` http
111
- GET /api/posts/{id }
133
+ GET /api/posts/{slug }
112
134
```
113
135
114
136
#### Create Post (Admin Only)
@@ -121,23 +143,45 @@ POST /api/posts
121
143
| :--- | :--- | :--- |
122
144
| ` title ` | ` string ` | ** Required** . Post title |
123
145
| ` slug ` | ` string ` | ** Required** . Post slug |
146
+ | ` excerpt ` | ` string ` | ** Required** . Post excerpt |
124
147
| ` content ` | ` string ` | ** Required** . Post content |
125
148
| ` category_id ` | ` integer ` | ** Required** . Category ID |
126
149
| ` status ` | ` string ` | ** Required** . Post status (draft/published) |
127
- | ` cover image ` | ` file ` | Optional. Post image |
150
+ | ` is_featured ` | ` boolean ` | Optional. Featured post status |
151
+ | ` cover_image ` | ` file ` | Optional. Post image |
128
152
129
153
#### Update Post (Admin Only)
130
154
131
155
``` http
132
156
PUT /api/posts/{slug}
133
157
```
134
158
159
+ Accepts the same parameters as the create endpoint.
160
+
135
161
#### Delete Post (Admin Only)
136
162
137
163
``` http
138
164
DELETE /api/posts/{slug}
139
165
```
140
166
167
+ Soft deletes the post. The post can be restored later.
168
+
169
+ #### Restore Post (Admin Only)
170
+
171
+ ``` http
172
+ POST /api/posts/{id}/restore
173
+ ```
174
+
175
+ Restores a soft-deleted post.
176
+
177
+ #### Force Delete Post (Admin Only)
178
+
179
+ ``` http
180
+ DELETE /api/posts/{id}/force-delete
181
+ ```
182
+
183
+ Permanently deletes the post.
184
+
141
185
### Categories
142
186
143
187
#### Get All Categories
@@ -149,7 +193,7 @@ GET /api/categories
149
193
#### Get Single Category
150
194
151
195
``` http
152
- GET /api/categories/{id }
196
+ GET /api/categories/{category }
153
197
```
154
198
155
199
#### Create Category (Admin Only)
@@ -166,19 +210,33 @@ POST /api/categories
166
210
#### Update Category (Admin Only)
167
211
168
212
``` http
169
- PUT /api/categories/{id }
213
+ PUT /api/categories/{category }
170
214
```
171
215
172
216
#### Delete Category (Admin Only)
173
217
174
218
``` http
175
- DELETE /api/categories/{id }
219
+ DELETE /api/categories/{category }
176
220
```
177
221
178
222
### Authentication
179
223
180
- All admin-only endpoints require authentication using a Bearer token. Include the token in the Authorization header:
224
+ All admin-only endpoints require authentication using a ** Bearer** token. Include the token in the Authorization header:
181
225
182
226
``` http
183
227
Authorization: Bearer <your_token>
184
- ```
228
+ ```
229
+
230
+ ### Error Responses
231
+
232
+ The API uses standard HTTP status codes to indicate the success or failure of requests:
233
+
234
+ - ` 200 OK ` - Request succeeded
235
+ - ` 201 Created ` - Resource created successfully
236
+ - ` 400 Bad Request ` - Invalid request parameters
237
+ - ` 401 Unauthorized ` - Missing or invalid authentication token
238
+ - ` 403 Forbidden ` - Authenticated but not authorized to access the resource
239
+ - ` 404 Not Found ` - Resource not found
240
+ - ` 422 Unprocessable Entity ` - Validation errors
241
+
242
+ Made with ❤️ by [ developermithu] ( https://developermithu.com )
0 commit comments