Skip to content
micayael edited this page Jan 15, 2012 · 18 revisions

Para conocer mejor los códigos que HTTP puede retornar se puede consultar http://es.wikipedia.org/wiki/Anexo:Códigos_de_estado_HTTP

Configuración del VirtualHost de Apache

<VirtualHost *:80>
    DocumentRoot /home/micayael/development/phpprojects/silex-projects/rest.micayael.com/web
    ServerName local.rest.micayael.com
    DirectoryIndex index.php
    ErrorLog /var/log/apache2/local.rest.micayael.com-error_log
    CustomLog /var/log/apache2/local.rest.micayael.com-access_log common
</VirtualHost>

Probar los servicios utilizando CURL

GET: Sin enviar los parámetros de autenticación

$ curl -i -X GET -H "Accept: application/json" http://local.rest.micayael.com/ver-comentarios.json
HTTP/1.1 401 Authorization Required
Date: Sun, 15 Jan 2012 21:20:19 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
www-authenticate: Basic realm="Autenticacion requerida"
cache-control: no-cache
Content-Length: 12
Content-Type: application/json

Unauthorized

GET: Enviando los parámetros de autenticación

$ curl -i --user "admin:123456" -X GET -H "Accept: application/json" http://local.rest.micayael.com/ver-comentarios.json
HTTP/1.0 200 OK
Date: Sun, 15 Jan 2012 21:16:21 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.3
cache-control: no-cache
Connection: close
Content-Type: application/json

[{"hilo":"2","comment_id":"2","comment_parent":"0","comment_date":"2010-08-20 19:57:06","comment_author":"John Dor","comment_author_email":"[email protected]","comment_author_url":"http:\/\/www.johndoe.net"}...

POST: Sin enviar los parámetros para la inserción

$ curl -i --user "admin:123456" -X POST http://local.rest.micayael.com/crear-comentario.html
HTTP/1.0 400 Bad Request
Date: Sun, 15 Jan 2012 21:15:32 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

Parametros insuficientes

POST: Enviando los parámetros para la inserción

$ curl -i --user "admin:123456" -X POST -d "comment[comment_post_id]=xxx&comment[comment_author]=xxx&comment[comment_author_email]=xxx&comment[comment_author_url]=xxx&comment[comment_author_IP]=xxx&comment[comment_content]=xxx&comment[comment_approved]=xxx&comment[comment_agent]=xxx&comment[comment_type]=xxx&comment[comment_parent]=xxx&comment[user_id]=xxx" http://local.rest.micayael.com/crear-comentario.html
HTTP/1.0 201 Created
Date: Sun, 15 Jan 2012 21:14:15 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

Comentario creado

PUT: En caso de no existir un ID a actualizar

$ curl -i --user "admin:123456" -X PUT -d "comment[comment_content]=xxx" http://local.rest.micayael.com/actualizar-comentario/0.html
HTTP/1.0 404 Not Found
Date: Sun, 15 Jan 2012 22:12:37 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

Comentario no encontrado

PUT: Actualizando correctamente el registro

$ curl -i --user "admin:123456" -X PUT -d "comment[comment_content]=xxx" http://local.rest.micayael.com/actualizar-comentario/2.html
HTTP/1.0 200 OK
Date: Sun, 15 Jan 2012 22:14:55 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: 32
Connection: close
Content-Type: text/html; charset=UTF-8

Comentario con ID: 2 actualizado

DELETE: En caso de no existir el ID a eliminar

$ curl -i --user "admin:123456" -X DELETE -d "comment[comment_content]=xxx" http://local.rest.micayael.com/eliminar-comentario/1.html
HTTP/1.0 404 Not Found
Date: Sun, 15 Jan 2012 22:23:14 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

Comentario no encontrado

DELETE: En caso de existir el ID a eliminar

$ curl -i --user "admin:123456" -X DELETE -d "comment[comment_content]=xxx" http://local.rest.micayael.com/eliminar-comentario/2.html
HTTP/1.0 200 OK
Date: Sun, 15 Jan 2012 22:25:24 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: 30
Connection: close
Content-Type: text/html; charset=UTF-8

Comentario con ID: 2 eliminado