Simple Chat Backend PHP
Written using PHP 7 and SQLite3.
How to run: copy all files into a webserver - tested using Apache
How to run tests: 'phpunit tests'
How to test: 'curl -X GET http://localhost:8080/api/getMessages?username=maxmouse'
- URL
<_/api/getUserByUserName>
-
Method:
<Get User by User Name>
GET
-
Data Params
Required:
username=[username]
-
Success Response:
- Code: 200
Content:{"id":42,"username":"maxmouse"}
- Code: 200
-
Error Response:
<If the user does NOT exist.>
-
Code: 404 Not Found
Content: `` -
Error Response:
<Username field is missing or invalid.>
- Code: 400 Bad Request
Content: ``
-
-
URL
</api/addUser>
-
Method:
<Add user>
POST
-
Data Params
Required:
username=[username]
-
Success Response:
- Code: 201
Content: ``
- Code: 201
-
Error Response:
<If the user data is invalid or username is already taken.>
- Code: 400 Bad Request
Content: ``
- Code: 400 Bad Request
-
URL
</api/getMessages>
-
Method:
GET
-
Data Params
Required:
username=[username]
-
Success Response:
- Code: 200
Content:[{"id":"5","user_id":"43","from_user":"42","message":"oioioio","time":"2018-12-03 00:43:59"},{"id":"4","user_id":"43","from_user":"42","message":"saiuho328","time":"2018-12-03 00:43:46"}]
- Code: 200
-
Error Response:
<If the user data is invalid or username is already taken.>
- Code: 400 Bad Request
Content: ``
- Code: 400 Bad Request
-
URL
</api/sendMessage>
-
Method:
<Send message to an user>
POST
-
Data Params
Required:
to=[username]
from=[username]
text=[message text]
-
Success Response:
- Code: 200
Content: ``
- Code: 200
-
Error Response:
<If the sender or recepient user does NOT exists in the database or any field is missing.>
- Code: 400 Bad Request
Content: ``
- Code: 400 Bad Request
-
Notes:
<Things to improve: unit tests, add functional tests, error handling.>