项目作者: joserafael

项目描述 :
test api rest in cakephp 3.4.x
高级语言: PHP
项目地址: git://github.com/joserafael/apidemocake3.git
创建时间: 2017-05-27T00:18:53Z
项目社区:https://github.com/joserafael/apidemocake3

开源协议:

下载


Prueba de API REST con CAKEPHP 3.4.x

Instalación

Clonar el proyecto:

  1. git clone https://github.com/joserafael/apidemocake3.git

Ir a la carpeta del proyecto:

  1. cd apidemocake3

Instalar cakephp y las dependencias con composer:

  1. composer install

Renombrar el archivo config/app.default.php a config/app.php configurar la base de datos en la línea 232:

  1. 'username' => 'my_app',
  2. 'password' => 'secret',
  3. 'database' => 'my_app',
  4. 'encoding' => 'utf8',
  5. 'timezone' => 'UTC',
  6. 'flags' => [],
  7. 'cacheMetadata' => true,
  8. 'log' => false,

Realizar la migración:

  1. bin/cake migrations migrate

Iniciar el servidor:

  1. bin/cake server

El URL principal es http://localhost:8765

Probar la API

Se recomienda usar POSTMAN

Crear un nuevo usuario:

POST: http://localhost:8765/users/add.json

Header: Content-Type: application/json

Body:

{
“username”:”usuario”,
“password”:”12345678”,
“active”:true,
“email”:”correo@correo.com”,
“is_superuser”:false
}

Iniciar sesión:

POST: http://localhost:8765/users/token.json

Header: Content-Type: application/json

Body:

{
“username”:”usuario”,
“password”:”12345678”

}

La respuesta sería algo así:

{
“success”: true,
“data”: {
“token”: “unaseriededigitoslargos”
}
}

Con el token asignado se pueden usar las tablas de contactos y paises en sus metodos respectivos.

En el header colocar:

Authorization: Bearer unaseriededigitoslargos

  1. Paginar los registros:
  2. GET http://localhost:8765/contactos.json
  3. GET http://localhost:8765/paises.json
  4. GET http://localhost:8765/users.json
  5. Ver un registro por ID:
  6. GET http://localhost:8765/contactos/view/{{id}}.json
  7. GET http://localhost:8765/paises/view/{{id}}.json
  8. GET http://localhost:8765/contactos/users/{{id}}.json
  9. Agregar un registro:
  10. POST GET http://localhost:8765/contactos/add.json
  11. POST GET http://localhost:8765/paises/add.json
  12. POST GET http://localhost:8765/users/add.json
  13. Editar un registro:
  14. POST http://localhost:8765/contactos/edit/{{id}}.json
  15. POST http://localhost:8765/paises/edit/{{id}}.json
  16. POST http://localhost:8765/users/edit/{{id}}.json
  17. Borrar un registro:
  18. POST http://localhost:8765/contactos/delete/{{id}}.json
  19. POST http://localhost:8765/paises/delete/{{id}}.json
  20. POST http://localhost:8765/users/delete/{{id}}.json

En caso de duda me pueden escribir a mi correo webmaster@joserafael.com.ve o a mi cuenta en Twitter: @joserafael