-
Notifications
You must be signed in to change notification settings - Fork 1
Home
fjalvarezdd edited this page Jan 2, 2013
·
4 revisions
php vendor/silex.phar version
Silex version 9ac208d 2012-12-21 07:30:14 +0100
To better understand the codes that can be returned HTTP you can check the following links:
- http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
- http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
- http://developer.yahoo.com/social/rest_api_guide/http-response-codes.html
- http://www.ietf.org/rfc/rfc2616.txt
- http://www.matlus.com/as-net-web-api-supporting-restful-crud-operations/
<VirtualHost *:80>
DocumentRoot /home/fjalvarezdd/development/phpprojects/silex-projects/SilexRestServer/web
ServerName local.SilexRestServer
DirectoryIndex index.php
ErrorLog /var/log/apache2/local.SilexRestServer-error_log
CustomLog /var/log/apache2/local.SilexRestServer-access_log common
<Directory "/home/fjalvarezdd/development/phpprojects/silex-projects/SilexRestServer/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
CREATE TABLE IF NOT EXISTS `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`author` varchar(3) NOT NULL,
`email` varchar(100) NOT NULL,
`content` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
$ curl -i -X GET -H "Accept: application/json" http://local.SilexRestServer/view-comments.json
HTTP/1.1 401 Authorization Required
Date: Tue, 31 Jan 2012 21:48:06 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
www-authenticate: Basic realm="Authentication required"
cache-control: no-cache
Content-Length: 12
Content-Type: application/json
Unauthorized
$ curl -i --user "admin:123456" -X GET -H "Accept: application/json" http://local.SilexRestServer/view-comments.json
HTTP/1.0 200 OK
Date: Tue, 31 Jan 2012 21:50:02 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Content-Length: 640
Connection: close
Content-Type: application/json
[{"id":"1","author":"xxx","email":"xxx","content":"xx'xx","created_at":"2012-12-30 19:38:30","updated_at":"2012-12-30 19:38:30"},{"id":"9","author":"xxx","email":"xxx","content":"xx'xx","created_at":"2012-12-30 19:36:56","updated_at":"2012-12-30 19:36:56"},{"id":"10","author":"xxx","email":"xxx","content":"xx'xx","created_at":"2012-12-30 19:37:08","updated_at":"2012-12-30 19:37:08"},{"id":"11","author":"xxx","email":"9","content":"xx'xx","created_at":"2012-12-30 19:48:18","updated_at":"2012-12-30 19:48:18"},{"id":"12","author":"aaa","email":"9","content":"xx'xx","created_at":"2012-12-30 19:48:36","updated_at":"2012-12-30 19:48:36"}]
$ curl -i --user "admin:123456" -X POST http://local.SilexRestServer/create-comment.html
HTTP/1.0 400 Bad Request
Date: Tue, 31 Jan 2012 21:51:28 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Vary: Accept-Encoding
Content-Length: 24
Connection: close
Content-Type: text/html; charset=UTF-8
Insufficient parameters
$ curl -i --user "admin:123456" -d "comment[author]=John Doe&comment[email]=fran@devaddiction.com&comment[content]=this is a test" -X POST http://local.SilexRestServer/create-comment.html
HTTP/1.0 201 Created
Date: Tue, 31 Jan 2012 21:53:08 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Vary: Accept-Encoding
Content-Length: 17
Connection: close
Content-Type: text/html; charset=UTF-8
X-Pad: avoid browser bug
Comment created
$ curl -i --user "admin:123456" -X PUT -d "comment[content]=this is a new test" http://local.SilexRestServer/update-comment/0.html
HTTP/1.0 404 Not Found
Date: Tue, 31 Jan 2012 21:59:06 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Vary: Accept-Encoding
Content-Length: 25
Connection: close
Content-Type: text/html; charset=UTF-8
X-Pad: avoid browser bug
Comment not found
$ curl -i --user "admin:123456" -X PUT -d "comment[content]=this is a new test" http://local.SilexRestServer/update-comment/1.html
HTTP/1.0 200 OK
Date: Tue, 31 Jan 2012 21:59:49 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Vary: Accept-Encoding
Content-Length: 33
Connection: close
Content-Type: text/html; charset=UTF-8
Comment with ID: 14 updated
$ curl -i --user "admin:123456" -X DELETE http://local.SilexRestServer/delete-comment/0.html
HTTP/1.0 404 Not Found
Date: Tue, 31 Jan 2012 22:00:47 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Vary: Accept-Encoding
Content-Length: 25
Connection: close
Content-Type: text/html; charset=UTF-8
X-Pad: avoid browser bug
Comment not found.````
$ curl -i --user "admin:123456" -X DELETE http://local.SilexRestServer/delete-comment/1.html
HTTP/1.0 200 OK
Date: Tue, 31 Jan 2012 22:01:16 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Vary: Accept-Encoding
Content-Length: 31
Connection: close
Content-Type: text/html; charset=UTF-8
Comment with ID: 14 deleted