edit README
This commit is contained in:
parent
cb4fa03a92
commit
2c113123b9
16
README.md
16
README.md
@ -17,11 +17,11 @@
|
||||
|
||||
</details></br>
|
||||
|
||||
### Instalacion
|
||||
### Instalación
|
||||
|
||||
Instalar [requerimientos](./requirements.txt) **en entorno virtual**
|
||||
|
||||
```py
|
||||
```sh
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
@ -40,9 +40,9 @@ django-admin startproject drf_course backend
|
||||
|
||||
Este proyecto consta de 2 aplicaciones.
|
||||
|
||||
La primera es el núcleo. Esta contendrá la lógica del contacto con el *endpoint*.
|
||||
La segunda será *ecommerce*. Esta contendrá la ĺógica del endpoint de los
|
||||
*items* y ordenes.
|
||||
La primera es el núcleo. Esta contendrá la lógica de **contacto** con el endpoint.
|
||||
La segunda será **ecommerce**. Esta contendrá la ĺógica del endpoint de los
|
||||
*items* y *ordenes*.
|
||||
|
||||
```sh
|
||||
cd backend
|
||||
@ -215,14 +215,14 @@ Importar modelo y registrar en [./backend/core/admin.py](./backend/core/admin.py
|
||||
|
||||
Crear las migraciones y migrar.
|
||||
|
||||
```py
|
||||
```sh
|
||||
./manage.py makemigrations
|
||||
./manage.py migrate
|
||||
```
|
||||
|
||||
Finalmente, crear **super usuario**.
|
||||
|
||||
```py
|
||||
```sh
|
||||
./manage.py createsuperuser
|
||||
```
|
||||
|
||||
@ -231,7 +231,7 @@ Finalmente, crear **super usuario**.
|
||||
**curl**
|
||||
|
||||
```sh
|
||||
curl -XPOST -H "Content-type: application/json" \
|
||||
curl -X POST -H "Content-type: application/json" \
|
||||
-d '{"name": "DevFzn", "message": "prueba", "email":"mail@mail.com"}' \
|
||||
'http://127.0.0.1:8000/contact/'
|
||||
```
|
||||
|
20
api_calls.sh
20
api_calls.sh
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# API Calls using curl and httpie
|
||||
# API Calls - curl
|
||||
|
||||
API_URL='http://127.0.0.1:8000'
|
||||
USER="$(read -p 'Username: ' && echo ${REPLY})"
|
||||
@ -9,7 +9,7 @@ PASS="$(read -s ; echo ${REPLY})"
|
||||
TOKEN=''
|
||||
|
||||
while :; do
|
||||
printf '\nLlamadas a API en %s\n' "${API_URL}"
|
||||
printf '\n\nLlamadas a API en %s\n' "${API_URL}"
|
||||
read -p 'URL ok? (Y/n/q)'
|
||||
case "${REPLY}" in
|
||||
[yY]|[sS]|[Ss][Ii]|[Yy][Ee][Ss]|'')
|
||||
@ -31,19 +31,19 @@ done
|
||||
|
||||
TOKEN="$(curl -sX POST -F "username=${USER}" -F "password=${PASS}" \
|
||||
"${API_URL}/api-token-auth/" | jq -r .'[]')"
|
||||
ITEM0_ID="$(curl -sX GET -H "Authorization: Token ${TOKEN}" "${API_URL}/item/" |
|
||||
ITEM_ID="$(curl -sX GET -H "Authorization: Token ${TOKEN}" "${API_URL}/item/" |
|
||||
jq -r '.data[-1].id')"
|
||||
ODER0_ID="$(curl -sX GET -H "Authorization: Token ${TOKEN}" "${API_URL}/order/" |
|
||||
ORDER_ID="$(curl -sX GET -H "Authorization: Token ${TOKEN}" "${API_URL}/order/" |
|
||||
jq -r '.data[-1].id')"
|
||||
|
||||
separator(){
|
||||
echo && printf '┄%.0s' {1..90} && echo
|
||||
echo && printf '┄%.0s' {1..85} && echo
|
||||
}
|
||||
|
||||
api_get_token(){
|
||||
separator && printf '%s\n' "${1}"
|
||||
printf 'curl -X POST -F "username=%s" -F "password=%s" "%s/api-token-auth/"\n' \
|
||||
"${USER}" "${PASS//*/XXXX}"
|
||||
"${USER}" "XXXXXXXX"
|
||||
curl -sX POST -F "username=${USER}" -F "password=${PASS}" \
|
||||
"${API_URL}/api-token-auth/" | jq
|
||||
}
|
||||
@ -65,7 +65,7 @@ api_order_call(){
|
||||
printf ' %s/order/\n' "${API_URL}"
|
||||
curl -sX POST -H 'Content-Type: application/json' \
|
||||
-H "Authorization: Token ${TOKEN}" \
|
||||
-d "{\"item\": \"${ITEM0_ID}\", \"quantity\": \"${4}\"}" \
|
||||
-d "{\"item\": \"${ITEM_ID}\", \"quantity\": \"${4}\"}" \
|
||||
"${API_URL}/${2}" | jq
|
||||
}
|
||||
|
||||
@ -91,10 +91,10 @@ api_contact_call(){
|
||||
|
||||
api_get_token "1) Devuelve el token"
|
||||
api_item_call "2) Devuelve todos los items" "item/"
|
||||
api_item_call "3) Devuelve el primer item" "item/${ITEM0_ID}/"
|
||||
api_order_call "4) Realiza un pedido" "order/" "${ITEM0_ID}" 1
|
||||
api_item_call "3) Devuelve el primer item" "item/${ITEM_ID}/"
|
||||
api_order_call "4) Realiza un pedido" "order/" "${ITEM_ID}" 1
|
||||
api_getorder_call "5) Devuelve todas las ordenes" "order/"
|
||||
api_getorder_call "6) Devuelve la primera orden" "order/${ODER0_ID}/"
|
||||
api_getorder_call "6) Devuelve la primera orden" "order/${ORDER_ID}/"
|
||||
api_contact_call "7) Crea un contacto" "DevFzn" "test contacto" "devfzn@mail.com"
|
||||
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user