Phalcon boilerplate application that provides a RESTful API using MongoDB.
- HTTP Methods
- GET
- POST
- PUT
- DELETE
- OPTIONS
- MongoDB
- Uses MongoDB with SSL support
- Security
- Whitelist IP address validation
- Token validation
- CRUD (Create, Read, Update and Delete)
- Provides sample for CRUD actions on a Model
- Logging
- Provides application logging
On my local machine I have the following installed.
- Apache 2.4.10
- PHP 5.5.x
- Phalcon 2.0.x
- MongoDB 3.0.x
- PHP MongoDB Database Driver
Here is sample configuration to get the API running on port 10060.
Listen 10060
<VirtualHost *:10060>
ServerName localhost:10060
ServerAdmin emad.najeeb@gmail.com
DocumentRoot "/Library/WebServer/Documents/phalcon-rest-boilerplate/"
DirectoryIndex "index.php"
<Directory "/Library/WebServer/Documents/phalcon-rest-boilerplate/">
Options +Indexes +FollowSymLinks +MultiViews +Includes
AllowOverride All
Require all granted
</Directory>
<IfModule mod_ssl.c>
SSLEngine On
SSLProxyEngine On
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile "/Users/emadnajeeb/Documents/ssl-certificates/local/server.crt"
SSLCertificateKeyFile "/Users/emadnajeeb/Documents/ssl-certificates/local/server.key"
</IfModule>
</VirtualHost>
I assume you already have Phalcon framework installed. If not, then follow instructions at Phalcon Website.
This boilerplate application uses MongoDB. Use the installation instructions on MongoDB Site. You can ofcouse use any database of your choice.
For Mac OS X, I used Homebrew.
brew update
brew install mongodb --with-openssl
Create the following supporting folders
cd phalcon-rest-boilerplate
mkdir logs
touch logs/app.log
chmod -R 777 logs
Here are the available REST API operations:
- GET /v1/identity/token
- OPTIONS /v1/identity/token
curl -k -v -X GET https://localhost:10060/v1/identity/token \
-H "Content-Type:application/json"
{
"status": "success",
"data": "jUd6jyPb1l3iJ3MUN3Z6Br8oiEEPq4A",
"error": null
}
- POST /v1/user
- GET /v1/user/
- PUT /v1/user/
- DELETE /v1/user/
- OPTIONS /v1/user
curl -k -v -X POST https://localhost:10060/v1/user \
-H "Content-Type:application/json" \
-H "X-CSRFToken:dDw1yRYL3G09XW6fQ0qBnMhSanyAstnG" \
-d '{
"name": "User Name"
}'
HTTP/1.1 201 Created
{
"status": "success",
"data": "{\"_id\":{\"$id\":\"56650acbbf664d2f78d63af1\"},\"name\":\"User Name\",\"createdDate\":{\"sec\":1449462475,\"usec\":911000},\"modifiedDate\":{\"sec\":1449462475,\"usec\":911000}}",
"error": null
}
curl -k -v -X GET https://localhost:10060/v1/user/566dab2cbf664dae7ad63af2 \
-H "Content-Type:application/json" \
-H "X-CSRFToken:dDw1yRYL3G09XW6fQ0qBnMhSanyAstnG"
HTTP/1.1 200 OK
{
"status": "success",
"data": "{\"_id\":{\"$id\":\"566dab2cbf664dae7ad63af2\"},\"name\":\"User Name\",\"createdDate\":{\"sec\":1449462475,\"usec\":911000},\"modifiedDate\":{\"sec\":1449462475,\"usec\":911000}}",
"error": null
}
curl -k -v -X PUT https://localhost:10060/v1/user/566dab2cbf664dae7ad63af2 \
-H "Content-Type:application/json" \
-H "X-CSRFToken:dDw1yRYL3G09XW6fQ0qBnMhSanyAstnG" \
-d '{
"name": "User Name update"
}'
HTTP/1.1 200 OK
{
"status": "success",
"data": "{\"_id\":{\"$id\":\"566dab2cbf664dae7ad63af2\"},\"name\":\"User Name update 1\",\"createdDate\":{\"sec\":1449462475,\"usec\":911000},\"modifiedDate\":{\"sec\":1449507337,\"usec\":226000}}",
"error": null
}
curl -k -v -X DELETE https://localhost:10060/v1/user/566dab2cbf664dae7ad63af2 \
-H "Content-Type:application/json" \
-H "X-CSRFToken:dDw1yRYL3G09XW6fQ0qBnMhSanyAstnG"
HTTP/1.1 200 OK
{
"status": "success",
"data": null,
"error": null
}
- Initial release