The assignment asked for a basic HTTP authentication, so simply add an Authorization
header equal to Basic some_hash
, where that hash is base64 of your_username:your_password
.
- GET /messages — show all messages
- GET /messages/archived — show archived messages
- GET /messages/:id — show a particular message
- PUT /messages/:id/read — mark message as read
- PUT /messages/:id/archive — mark message as archived
To paginate apply GET parameters page_start
and page_length
. If page_length
is
missing pagination is considered to be off. If more data is present on the next pages
Link
header will be sent according to RFC 5988.
I assume you have PHP, Nginx an MySQL already installed and everything is running on a Debian-like Linux machine. If not, well, anyway you know what to do. :P
- Copy file
App/config.dist.php
toApp/config.php
and adjust fields in the latter. - Import schema to create a database and a table
mysql -u username -p'password' < docs/schema.sql
- Add
127.0.0.1 api.local-firm.dev
line to/etc/hosts
file. - Add a web server config:
server
{
listen 80;
server_name api.local-firm.dev;
root /path/to/public/folder;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$
{
fastcgi_pass unix:/path/to/php/socket/file;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
- Reload Nginx with
service nginx reload
. - Assure CLI file is executable by
chmod +x ./cli
(or simply run it asphp cli
next time you need it).
The API is supposed to be up before testing. Run ./cli test all
to perform all tests.
The CLI will both display its log and return a corresponding return code that can
be used further. Tests are supposed to be run in development environment and their
performance is not always optimized for production.
- Get some tool to work with APIs, like Postman.
- Run
./cli admin populate docs/messages_sample.json
to populate the database. - ...
- PROFIT!