Skip to content

sas05/test-simple-rest

Repository files navigation

Rest Server Test

####How do I run it? After download from the root folder of the project, run the following commands to install the php dependencies, import some data, and run a local php server.

You need at least php 5.5.* with SQLite extension enabled and Composer

composer install 
sqlite3 app.db < resources/sql/schema.sql
php -S 0:8000 -t web/

Your api is now available at http://localhost:8000/api/v1.

####Run tests Some tests were written, and all CRUD operations are fully tested :)

From the root folder run the following command to run tests.

vendor/bin/phpunit 

####What you will get The api will respond to

PUT     ->   http://localhost:8000/api/v1/items/save *this should be post but I make it PUT request because it asked in the exam paper*
GET     ->   http://localhost:8000/api/v1/items/list
PUT     ->   http://localhost:9001/api/v1/items/update/{id}
DELETE  ->   http://localhost:9001/api/v1/items
POST    ->   http://localhost:9001/api/v1/cart/add
DELETE  ->   http://localhost:9001/api/v1/cart/DELETE

Your request should have 'Content-Type: application/json' header. Your api is CORS compliant out of the box, so it's capable of cross-domain communication.

Try with curl:

#GET
curl http://localhost:8000/api/v1/items/lists -H 'Content-Type: application/json' -w "\n"

#POST (insert)
curl -X PUT http://localhost:8000/api/v1/items/save -d '{"name":"foo", "description": "shoes", "price": 30}' -H 'Content-Type: application/json' -w "\n"

#POST (insert)
curl -X PUT http://localhost:9001/api/v1/cart/add -d '{"customer_id":1, "item_id":}' -H 'Content-Type: application/json' -w "\n"

Under the resources folder you can find a .htaccess file to put the api in production.

####Contributing

Fell free to contribute, fork, pull request, hack. Thanks!

####Author

License

see LICENSE file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages