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