User API is a RESTful API for manage user profiles (id, name, email, image) using PHP and MySQL database.
This API was built with Slim 3 PHP framework. It uses composer as a Dependency Manager and supports PSR-2 and PSR-4 coding standards. Finally, this API has unit tests built with PHPUnit and Guzzle (PHP Http client).
Because of lack time, this API don't have oAuth 2 authentication, maybe for the next version.
PHP 5.6.30 and mysqli activated MySQL 5.5.16 or greater
- Create database and table executing the "/userprofileapidb.sql" file in MySQL database
- Go to the root of apache documents
- Clone the repository in this place
- Edit "/app/api/dbConfig.php" file and change the constants in order to connect with database (HOST,USER,PASSWORD)
- Go to "userAPI" folder and execute this command in your CLI to start the application php -S localhost:8050 -t public
-
Go to your browser and copy-paste the URL "http://localhost:8050/api/userProfile"
-
If you want to run the unit tests do the following 2.1 Go to the "userAPI" folder inside of apache documents folder 2.2 Execute the next command in your CLI: if you have linux: php vendor/bin/phpunit tests/userProfileTests.php
if you have windows: phpunit.bat tests\userProfileTests.php
-
You also can use Postman Extension (web browser) for testing, the available routes are:
GET http://localhost:8050/api/userProfile
In this case when there are rows in database, the result is in json format and look like this: [ { id: "1", name: "UserProfileTest363", email: "UserProfileTest363@gmail.com", Image: "http://someserver/images/UserProfileTest363.jpeg" }, { id: "2", name: "UserProfileTest366", email: "UserProfileTest366@hotmail.com", Image: "http://someserver/images/UserProfileTest366.jpg" } ] If this case when there are no rows in database, the result is in json format and look like this: ["No results found."]
GET http://localhost:8050/api/userProfile/3
In this case when the rows exists in database, the result is in json format and look like this: [ { id: "3", name: "UserProfileTest249", email: "UserProfileTest249@gmail.com", Image: "http://someserver/images/UserProfileTest249.jpeg" } ] If this case when the row don't exists in database, the result is in json format and look like this: ["No results found."]
POST http://localhost:8050/api/userProfile
In this case is necessary to send a json array data like this: [ { id: "20", name: "UserProfileTest149", email: "UserProfileTest149@hotmail.com", Image: "http://someserver/images/UserProfileTest149.png" } ] The id key optional if you don't send it, database creates it for you. If the request was successful, the result will look like this: ["Successful insert"] In this case when the row don't inserts in database, the result is in json format and look like these: ["name argument is required"] ["invalid email address"] ["An error has occurred. "]
PUT http://localhost:8050/api/userProfile
In this case is necessary to send a json array data like this: [ { id: "21", name: "UserProfileTest165", email: "UserProfileTest165@hotmail.com", Image: "http://someserver/images/UserProfileTest165.png" } ] If the request was successful, the result will look like this: ["Successful update"] In this case when the row don't updates in database, the result is in json format and look like these: ["name argument is required"] ["invalid email address"] ["An error has occurred. "]
DELETE http://localhost:8050/api/userProfile/8
If the request was successful, the result will look like this: ["Successful delete"] In this case when the row don't deletes in database, the result is in json format and look like these: ["id argument is required"] ["An error has occurred. "]
Edwuin Gutierrez edwinguti86@gmail.com
Copyright(c) 2017 MIT License