Skip to content

duvanbotello/guane-intern-fastapi

Repository files navigation

Diseño de una API REST con el framework FastAPI de python

Para esta prueba se requiere conocimiento en python, protocolo http, verbos http (GET, POST, PUT, DELETE). Haciendo uso del framework de desarrollo para python FastAPI, se desea que el participante desarrolle las siguientes funcionalidades:

  1. Obtener un listado de
  2. Obtener la información de por id
  3. Actualizar la información de una
  4. Borrar la

La con la que vamos a trabajar tiene el siguiente modelo de datos:

{
    id: string
    name: string,
    picture: string,
    create_date: string,
    is adopted: bool
}

La entidad que vamos a manejar en esta ocasión es Dog. Para cumplir las necesidades listadas en las funcionalidades se requiere tener los siguientes ENPOINTS:

  • GET -> /api/dogs : Obtener una listado.
  • GET -> /api/dogs/{name} : Obtener una entrada a partir del nombre.
  • GET -> /api/dogs/is_adopted : Obtener todas las entradas donde la bandera is_adopted sea
  • True.
  • POST -> /api/dogs/{name}: Guardar un registro según el esquema de arriba. El campo picture
  • se debe rellenar con una consulta al API externa https://dog.ceo/api/breeds/image/random.
  • PUT -> /api/dogs/{name}: Actualizar un registro según el nombre.
  • DELETE -> /api/dogs/{name}: Borrar un registro según el nombre.

Un ejemplo de registro:

{
    "name": "Lazy",
    "picture": "https:\/\/images.dog.ceo\/breeds\/papillon\/n02086910_6483.jpg",
    "create_date": "2020-02-20 20:58:55.164954"
    "is_adopted": True,
}

Los datos pueden ser guardados utilizando una base de datos (la que el participante desee), o puede optar por hacer uso lista en memoria.

OPCIONAL

  • Las rutas para ingresar un nuevo camino (el POST) debería estar protegida con alguna política de seguridad mediante recomiendo usar JWT.
  • Realizar dockerfile y docker-compose de la aplicación.
  • Desarrollar un Worker con Celery cuando se llame la función POST. Las tareas en segundo plano tienen sentido para actividades que se pueden realizar de forma asíncrona. Puedes simular una latencia en el registro de los perros de unos segundos para verificar que el "Worker" está funcionando.
  • Añadir una nueva entidad llamada User con sus respectivos endpoints de CRUD básico. Esta entidad tendrá una relación de uno a muchos con la entidad Dog, es decir, un User puede tener uno o muchos Dogs (para esto solo se requiere que la entidad Dog se agregue un nuevo campo llamado id_user y guarde el id de un usuario). Los campos para la entidad User pueden ser: id, nombre, apellido, email.

Finalmente, el código debe estar en un repositorio en tu GIT personal llamado "guane-intern-fastapi". También debes seguir el estándar del PEP8 en la codificación con lineamientos de buenas prácticas.

Autenticación

JWT

JWT (JSON Web Token) es un estándar qué está dentro del documento RFC 7519.

En el mismo se define un mecanismo para poder propagar entre dos partes, y de forma segura, la identidad de un determinado usuario, además con una serie de claims o privilegios.

Estos privilegios están codificados en objetos de tipo JSON, que se incrustan dentro de del payload o cuerpo de un mensaje que va firmado digitalmente.

Instalacion del proyecto


$ docker-compose up -d

Hecho con ♥ por Duvan Botello



title: FastAPI v0.1.0 language_tabs:

  • python: Python

search: true highlight_theme: darkula headingLevel: 2


FastAPI v0.1.0

Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.

Authentication

  • oAuth2 authentication.

    • Flow: password

    • Token URL = token

Scope Scope Description

Default

login_for_access_token_token_post

Code samples

# You can also use wget
curl -X POST /token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Accept: application/json'
POST /token HTTP/1.1

Content-Type: application/x-www-form-urlencoded
Accept: application/json
const inputBody = '{
  "grant_type": "string",
  "username": "string",
  "password": "string",
  "scope": "",
  "client_id": "string",
  "client_secret": "string"
}';
const headers = {
  'Content-Type':'application/x-www-form-urlencoded',
  'Accept':'application/json'
};

fetch('/token',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/x-www-form-urlencoded',
  'Accept' => 'application/json'
}

result = RestClient.post '/token',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Accept': 'application/json'
}

r = requests.post('/token', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','/token', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/token");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/x-www-form-urlencoded"},
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "/token", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

POST /token

Login For Access Token

Body parameter

grant_type: string
username: string
password: string
scope: ""
client_id: string
client_secret: string

Parameters

Name In Type Required Description
body body Body_login_for_access_token_token_post true none

Example responses

200 Response

{
  "access_token": "string",
  "token_type": "string"
}

Responses

Status Meaning Description Schema
200 OK Successful Response Token
422 Unprocessable Entity Validation Error HTTPValidationError
This operation does not require authentication

read_dogs_api_dogs_get

Code samples

# You can also use wget
curl -X GET /api/dogs \
  -H 'Accept: application/json'
GET /api/dogs HTTP/1.1

Accept: application/json
const headers = {
  'Accept':'application/json'
};

fetch('/api/dogs',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get '/api/dogs',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('/api/dogs', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('GET','/api/dogs', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/dogs");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "/api/dogs", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

GET /api/dogs

Read Dogs

Parameters

Name In Type Required Description
skip query integer false none
limit query integer false none

Example responses

200 Response

[
  {
    "name": "string",
    "picture": "string",
    "create_date": "string",
    "is_adopted": true,
    "id": 0,
    "id_user": 0
  }
]

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
422 Unprocessable Entity Validation Error HTTPValidationError

Response Schema

Status Code 200

Response Read Dogs Api Dogs Get

Name Type Required Restrictions Description
Response Read Dogs Api Dogs Get [Dogs] false none none
» Dogs Dogs false none none
»» name string true none none
»» picture string true none none
»» create_date string true none none
»» is_adopted boolean true none none
»» id integer true none none
»» id_user integer true none none
This operation does not require authentication

read_dog_api_dogs__name__get

Code samples

# You can also use wget
curl -X GET /api/dogs/{name} \
  -H 'Accept: application/json'
GET /api/dogs/{name} HTTP/1.1

Accept: application/json
const headers = {
  'Accept':'application/json'
};

fetch('/api/dogs/{name}',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get '/api/dogs/{name}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('/api/dogs/{name}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('GET','/api/dogs/{name}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/dogs/{name}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "/api/dogs/{name}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

GET /api/dogs/{name}

Read Dog

Parameters

Name In Type Required Description
name path string true none

Example responses

200 Response

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id": 0,
  "id_user": 0
}

Responses

Status Meaning Description Schema
200 OK Successful Response Dogs
422 Unprocessable Entity Validation Error HTTPValidationError
This operation does not require authentication

edit_dogs_api_dogs__name__put

Code samples

# You can also use wget
curl -X PUT /api/dogs/{name} \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
PUT /api/dogs/{name} HTTP/1.1

Content-Type: application/json
Accept: application/json
const inputBody = '{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id_user": 0
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/api/dogs/{name}',
{
  method: 'PUT',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.put '/api/dogs/{name}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.put('/api/dogs/{name}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('PUT','/api/dogs/{name}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/dogs/{name}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("PUT");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("PUT", "/api/dogs/{name}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

PUT /api/dogs/{name}

Edit Dogs

Body parameter

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id_user": 0
}

Parameters

Name In Type Required Description
name path string true none
body body DogsCreate true none

Example responses

200 Response

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id": 0,
  "id_user": 0
}

Responses

Status Meaning Description Schema
200 OK Successful Response Dogs
422 Unprocessable Entity Validation Error HTTPValidationError
To perform this operation, you must be authenticated by means of one of the following methods: OAuth2PasswordBearer

create_dogs_api_dogs__name__post

Code samples

# You can also use wget
curl -X POST /api/dogs/{name} \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
POST /api/dogs/{name} HTTP/1.1

Content-Type: application/json
Accept: application/json
const inputBody = '{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id_user": 0
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/api/dogs/{name}',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.post '/api/dogs/{name}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.post('/api/dogs/{name}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','/api/dogs/{name}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/dogs/{name}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "/api/dogs/{name}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

POST /api/dogs/{name}

Create Dogs

Body parameter

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id_user": 0
}

Parameters

Name In Type Required Description
body body DogsCreate true none

Example responses

200 Response

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id": 0,
  "id_user": 0
}

Responses

Status Meaning Description Schema
200 OK Successful Response Dogs
422 Unprocessable Entity Validation Error HTTPValidationError
To perform this operation, you must be authenticated by means of one of the following methods: OAuth2PasswordBearer

delete_dogs_api_dogs__name__delete

Code samples

# You can also use wget
curl -X DELETE /api/dogs/{name} \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
DELETE /api/dogs/{name} HTTP/1.1

Accept: application/json
const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/api/dogs/{name}',
{
  method: 'DELETE',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.delete '/api/dogs/{name}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.delete('/api/dogs/{name}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('DELETE','/api/dogs/{name}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/dogs/{name}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("DELETE");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("DELETE", "/api/dogs/{name}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

DELETE /api/dogs/{name}

Delete Dogs

Parameters

Name In Type Required Description
name path string true none

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
422 Unprocessable Entity Validation Error HTTPValidationError

Response Schema

To perform this operation, you must be authenticated by means of one of the following methods: OAuth2PasswordBearer

read_dogs_api_dogs_is_adopted_get

Code samples

# You can also use wget
curl -X GET /api/dogs/is_adopted \
  -H 'Accept: application/json'
GET /api/dogs/is_adopted HTTP/1.1

Accept: application/json
const headers = {
  'Accept':'application/json'
};

fetch('/api/dogs/is_adopted',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get '/api/dogs/is_adopted',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('/api/dogs/is_adopted', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('GET','/api/dogs/is_adopted', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/dogs/is_adopted");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "/api/dogs/is_adopted", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

GET /api/dogs/is_adopted

Read Dogs

Parameters

Name In Type Required Description
is_adopted query boolean false none

Example responses

200 Response

[
  {
    "name": "string",
    "picture": "string",
    "create_date": "string",
    "is_adopted": true,
    "id": 0,
    "id_user": 0
  }
]

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
422 Unprocessable Entity Validation Error HTTPValidationError

Response Schema

Status Code 200

Response Read Dogs Api Dogs Is Adopted Get

Name Type Required Restrictions Description
Response Read Dogs Api Dogs Is Adopted Get [Dogs] false none none
» Dogs Dogs false none none
»» name string true none none
»» picture string true none none
»» create_date string true none none
»» is_adopted boolean true none none
»» id integer true none none
»» id_user integer true none none
This operation does not require authentication

read_users_api_users_get

Code samples

# You can also use wget
curl -X GET /api/users \
  -H 'Accept: application/json'
GET /api/users HTTP/1.1

Accept: application/json
const headers = {
  'Accept':'application/json'
};

fetch('/api/users',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get '/api/users',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('/api/users', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('GET','/api/users', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/users");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "/api/users", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

GET /api/users

Read Users

Parameters

Name In Type Required Description
skip query integer false none
limit query integer false none

Example responses

200 Response

[
  {
    "name": "string",
    "last_name": "string",
    "email": "string",
    "id": 0,
    "dogs": []
  }
]

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
422 Unprocessable Entity Validation Error HTTPValidationError

Response Schema

Status Code 200

Response Read Users Api Users Get

Name Type Required Restrictions Description
Response Read Users Api Users Get [Users] false none none
» Users Users false none none
»» name string true none none
»» last_name string true none none
»» email string true none none
»» id integer true none none
»» dogs [Dogs] false none none
»»» Dogs Dogs false none none
»»»» name string true none none
»»»» picture string true none none
»»»» create_date string true none none
»»»» is_adopted boolean true none none
»»»» id integer true none none
»»»» id_user integer true none none
This operation does not require authentication

edit_user_api_users__id_user__put

Code samples

# You can also use wget
curl -X PUT /api/users/{id_user} \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
PUT /api/users/{id_user} HTTP/1.1

Content-Type: application/json
Accept: application/json
const inputBody = '{
  "name": "string",
  "last_name": "string",
  "email": "string"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/api/users/{id_user}',
{
  method: 'PUT',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.put '/api/users/{id_user}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.put('/api/users/{id_user}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('PUT','/api/users/{id_user}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/users/{id_user}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("PUT");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("PUT", "/api/users/{id_user}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

PUT /api/users/{id_user}

Edit User

Body parameter

{
  "name": "string",
  "last_name": "string",
  "email": "string"
}

Parameters

Name In Type Required Description
id_user path integer true none
body body UsersCreate true none

Example responses

200 Response

{
  "name": "string",
  "last_name": "string",
  "email": "string",
  "id": 0,
  "dogs": []
}

Responses

Status Meaning Description Schema
200 OK Successful Response Users
422 Unprocessable Entity Validation Error HTTPValidationError
To perform this operation, you must be authenticated by means of one of the following methods: OAuth2PasswordBearer

create_user_api_users__id_user__post

Code samples

# You can also use wget
curl -X POST /api/users/{id_user} \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
POST /api/users/{id_user} HTTP/1.1

Content-Type: application/json
Accept: application/json
const inputBody = '{
  "name": "string",
  "last_name": "string",
  "email": "string"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/api/users/{id_user}',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.post '/api/users/{id_user}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.post('/api/users/{id_user}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','/api/users/{id_user}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/users/{id_user}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "/api/users/{id_user}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

POST /api/users/{id_user}

Create User

Body parameter

{
  "name": "string",
  "last_name": "string",
  "email": "string"
}

Parameters

Name In Type Required Description
id_user path integer true none
body body UsersCreate true none

Example responses

200 Response

{
  "name": "string",
  "last_name": "string",
  "email": "string",
  "id": 0,
  "dogs": []
}

Responses

Status Meaning Description Schema
200 OK Successful Response Users
422 Unprocessable Entity Validation Error HTTPValidationError
To perform this operation, you must be authenticated by means of one of the following methods: OAuth2PasswordBearer

delete_user_api_users__id_user__delete

Code samples

# You can also use wget
curl -X DELETE /api/users/{id_user} \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
DELETE /api/users/{id_user} HTTP/1.1

Accept: application/json
const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/api/users/{id_user}',
{
  method: 'DELETE',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.delete '/api/users/{id_user}',
  params: {
  }, headers: headers

p JSON.parse(result)
import requests
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.delete('/api/users/{id_user}', headers = headers)

print(r.json())
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('DELETE','/api/users/{id_user}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
URL obj = new URL("/api/users/{id_user}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("DELETE");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("DELETE", "/api/users/{id_user}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

DELETE /api/users/{id_user}

Delete User

Parameters

Name In Type Required Description
id_user path integer true none

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
422 Unprocessable Entity Validation Error HTTPValidationError

Response Schema

To perform this operation, you must be authenticated by means of one of the following methods: OAuth2PasswordBearer

Schemas

Body_login_for_access_token_token_post

{
  "grant_type": "string",
  "username": "string",
  "password": "string",
  "scope": "",
  "client_id": "string",
  "client_secret": "string"
}

Body_login_for_access_token_token_post

Properties

Name Type Required Restrictions Description
grant_type string false none none
username string true none none
password string true none none
scope string false none none
client_id string false none none
client_secret string false none none

Dogs

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id": 0,
  "id_user": 0
}

Dogs

Properties

Name Type Required Restrictions Description
name string true none none
picture string true none none
create_date string true none none
is_adopted boolean true none none
id integer true none none
id_user integer true none none

DogsCreate

{
  "name": "string",
  "picture": "string",
  "create_date": "string",
  "is_adopted": true,
  "id_user": 0
}

DogsCreate

Properties

Name Type Required Restrictions Description
name string true none none
picture string true none none
create_date string true none none
is_adopted boolean true none none
id_user integer true none none

HTTPValidationError

{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}

HTTPValidationError

Properties

Name Type Required Restrictions Description
detail [ValidationError] false none none

Token

{
  "access_token": "string",
  "token_type": "string"
}

Token

Properties

Name Type Required Restrictions Description
access_token string true none none
token_type string true none none

Users

{
  "name": "string",
  "last_name": "string",
  "email": "string",
  "id": 0,
  "dogs": []
}

Users

Properties

Name Type Required Restrictions Description
name string true none none
last_name string true none none
email string true none none
id integer true none none
dogs [Dogs] false none none

UsersCreate

{
  "name": "string",
  "last_name": "string",
  "email": "string"
}

UsersCreate

Properties

Name Type Required Restrictions Description
name string true none none
last_name string true none none
email string true none none

ValidationError

{
  "loc": [
    "string"
  ],
  "msg": "string",
  "type": "string"
}

ValidationError

Properties

Name Type Required Restrictions Description
loc [string] true none none
msg string true none none
type string true none none

About

prueba técnica guane Enterprises

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published