RESTful Bookmarks PHP Slim
TODO:
- review and update FrontEnd
Sample application to bookmark links, where interface build with Angular.js + Twitter Bootstrap and server powered by PHP with Slim Framework, serving JSON by REST URLs.
Install Guide
Clone
$ git clone https://github.com/erkobridee/restful-bookmarks-phpslim.git
$ cd restful-bookmarks-phpslim/
Create Mysql Database
$ mysql -u DBUSERNAME -p MYSQLPASSWORD -e 'CREATE DATABASE bookmarks;'
$ mysql -u DBUSERNAME -p MYSQLPASSWORD bookmarks < bookmarks.sql
Mysql connections
edit user DBUSERNAME
and MYSQLPASSWORD
in api/dao/BookmarkDAO.php
...
private function getDBConn()
{
$dbhost="127.0.0.1";
$dbuser="DBUSERNAME";
$dbpass="MYSQLPASSWORD";
$dbname="bookmarks";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
...
XAMPP
- Put project structure inside XAMPP /htdocs directory
Nginx example configuration
server {
listen 127.0.0.1:80;
access_log /var/www/restful-bookmarks-phpslim/log/access.log;
error_log /var/www/restful-bookmarks-phpslim/log/error.log warn;
server_name restful-bookmarks-phpslim;
root /var/www/restful-bookmarks-phpslim/public/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$request_uri;
location /rest/ {
try_files /rest/$uri $uri/ /rest/index.php?$request_uri;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^/rest/(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
}
}
Development with Sublime Text
-
On Sublime Text, in menu: File > Open... select project directory location in you computer
-
And happy coding :)
License
MIT : http://erkobridee.mit-license.org
Project build with
-
IDE
-
Client
-
AngularJS 1.2.1
-
-
Server
Helpful posts
-
Vedovelli - Introdução ao AngularJS (pt_BR) | based in how to configure Slim Framework, from this github - crud angular project
-
Recommended reading : JavaScript Patterns Collection
Project REST URLs
HTTP Verbs
-
GET - retrieve 1 or more bookmarks
-
.../rest/bookmarks/ - list all bookmarks
-
.../rest/bookmarks/{id} - retrieve bookmark by ID
-
.../rest/bookmarks/search/{name} - retrieve bookmarks list filtering by name
-
-
POST - insert new one
- .../rest/bookmarks/ - sent inside request body
-
PUT - updates an existing
- .../rest/bookmarks/{id} - sent inside request body
-
DELETE - remove bookmark by ID
Project Structure
- Must have Slim Framework/Install
restful-bookmarks-phpslim/
rest/
dao/
BookmarkDAO.php
Slim/
# Slim Framework files
.htacess # URLs map for Apache (XAMPP)
index.php # slim routes config
app/
# application files
shared/
# shared files with any future project
vendor/
# libs
index.html
require.config.js # require.js app config file