taravel/16. `docs/api.md

72 lines
2.4 KiB
Markdown

# API Documentation
## Authentication
### POST /api/login
- **Description**: Authenticate a user and generate a token.
- **Request Body**: JSON object with `email` and `password`.
- **Response**: JSON object with the generated token.
### POST /api/logout
- **Description**: Logout the user and revoke the token.
- **Response**: JSON object with a success message.
### Obtaining an Admin Token
- **Description**: To obtain a token for an admin user, follow these steps:
1. **Ensure the Admin User Exists**: Make sure there is an admin user in the database. If not, create one using the following command:
```bash
php artisan tinker
$user = new App\Models\User;
$user->name = 'Admin User';
$user->email = 'admin@example.com';
$user->password = bcrypt('password');
$user->role = 'admin';
$user->save();
exit
```
2. **Authenticate the Admin User**: Use the `/api/login` endpoint to authenticate the admin user and obtain the token. Send a POST request with the admin user's credentials:
```bash
curl -X POST http://your-app-url/api/login -H "Content-Type: application/json" -d '{"email":"admin@example.com","password":"password"}'
```
3. **Response**: The response will include a JSON object with the generated token:
```json
{
"token": "your-generated-token"
}
```
## Admin Management
### GET /api/admin/users
- **Description**: Get a list of users (restricted to member users).
- **Response**: JSON object with a list of users.
### POST /api/admin/users/{user}/activate
- **Description**: Activate a user (restricted to member users).
- **Response**: JSON object with a success message.
### POST /api/admin/users/{user}/deactivate
- **Description**: Deactivate a user (restricted to member users).
- **Response**: JSON object with a success message.
## Frontend API
### GET /api/frontend
- **Description**: Get frontend data.
- **Response**: JSON object with a message.
### POST /api/frontend
- **Description**: Store frontend data.
- **Request Body**: JSON object with required fields.
- **Response**: JSON object with a success message.
## Backend API
### GET /api/backend
- **Description**: Get backend data.
- **Response**: JSON object with a message.
### POST /api/backend
- **Description**: Store backend data.
- **Request Body**: JSON object with required fields.
- **Response**: JSON object with a success message.