This is an example of a RESTful api created in php using the slim4 framework.
- configure
DB_PATH
andJWT_KEY
inapp/env/.env
- if using docker, add
127.0.0.1 slimchat.local
to/etc/hosts
There are 2 ways to use it. You can either use via docker or manually
Few changes required for manual setup
DB_PATH=<absolute-path-to-this-project-root>/app/src/Database/database.db
JWT_KEY=my_secret_key
BASE_URI=http://localhost:8000
To run the app:
$ cd app
$ composer start
To run unit tests:
The server needs to be running for running unit tests
composer test
Few changes required for docker setup
- add hosts to /etc/hosts
add the following line -
$ sudo vi /etc/hosts
127.0.0.1 slimchat.local
- .env changes
DB_PATH=/app/src/Database/database.db JWT_KEY=my_secret_key BASE_URI=http://slimchat.local:8000
To run the app:
It will create 2 services - 1 nginx and 1 php.
$ docker compose up -d
To run unit tests:
The server needs to be running for running unit tests
composer test
You can download the postman collection shared with you to run the tests
NOTE\
- All routes except the Create User route will require a Bearer Token to be set with the request.
- When you create a user using the Create User route, you will get a token in the response.
- Please use this token for all subsequent reuqests.
-
Create User:
POST /api/v1/users
-
Get User:
GET /api/v1/users/{id}
-
Get Users:
GET /api/v1/users
-
Delete User:
DELETE /api/v1/users/{id}
-
Create Chat:
POST /api/v1/chats
-
Add User to Chat:
POST /api/v1/chats/{chatId}/users
-
Get a Chat:
GET /api/v1/chats/{chatId}
-
Get all Chats:
GET /api/v1/chats
-
Get Chats of User:
GET /api/v1/chats/user/{userId}
-
Get Users in Chat:
GET /api/v1/chats/{chatId}/users
-
Delete Chat:
DELETE /api/v1/chats/{chatId}
-
Create Message:
POST /api/v1/chats/{chatId}/{userId}/messages
-
Get messages of Chat:
GET /api/v1/chats/{chatId}/messages
-
Get messages of Chat with offset:
GET /api/v1/chats/{chatId}/messages?lastMessageId=5