User Management API is a PHP-based web API for handling user-related operations, such as creating, updating, deleting, and retrieving user information.
- Create a new user
 - Update user details
 - Delete a user
 - Retrieve user information
 - List all users
 
- PHP with PDO for database interaction
 - MySQL for user data storage
 
git clone https://github.com/mouraleonardo/user-management-api.git
Before running the API, you'll need to set up a MySQL database and update the connection details in the code. Follow these steps:
- Open your preferred MySQL database management tool.
 - Copy and paste the content of the users.sql file into the query window.
 - Execute the SQL statements to create the vaulteyes database and the users table.
 
Notes:
- The provided script includes the necessary SQL statements for creating the vaulteyes database and the users table.
 - It also populates the users table with sample data.
 
Run the API on a PHP-supported server environment (e.g., WAMP, XAMPP).
Additionally, here's an example of an API endpoint you can use:
- 
Endpoint:
POST /api
 - 
Request Body:
json
 - 
{ "action": "createUser", "firstName": "John", "lastName": "Doe", "username": "johndoe", "email": "[email protected]", "password": "securepassword" }- Response:
 
json
 - 
{ "message": "User created successfully", "userId": 123 } 
- 
Endpoint:
POST /api
 - 
Request Body:
json
 - 
{ "action": "updateUser", "userId": 123, "firstName": "Updated", "lastName": "User", "username": "updateduser", "email": "[email protected]", "password": "newsecurepassword" }- Response:
 
json
 - 
{ "message": "User updated successfully", "userId": 123 } 
- 
Endpoint:
POST /api
 - 
Request Body:
json
 - 
{ "action": "deleteUser", "userId": 123 }- Response:
 
json
 - 
{ "message": "User deleted successfully" } 
- 
Endpoint:
POST /api
 - 
Request Body:
json
 - 
{ "action": "getUser", "searchTerm": "johndoe" }- Response:
 
json
 - 
{ "userId": 123, "firstName": "John", "lastName": "Doe", "username": "johndoe", "email": "[email protected]" } 
- 
Endpoint:
POST /api
 - 
Request Body:
json
 - 
{ "action": "listUsers" }- Response:
 
json
 - 
[ { "userId": 123, "firstName": "John", "lastName": "Doe", "username": "johndoe", "email": "[email protected]" }, // Additional users... ] 
- 
Passwords:
- Passwords are securely hashed using the bcrypt algorithm to ensure strong protection against unauthorized access.
 
 - 
Validation:
- Validation checks are implemented to prevent duplicate usernames and emails during both user creation and update operations. This helps maintain the uniqueness of user credentials in the system.
 
 - 
Error Handling:
- The API returns detailed error messages to guide clients in case of issues, promoting transparency and aiding in effective issue resolution.
 
 
This project is licensed under the MIT License - see the LICENSE file for details.