Coder Social home page Coder Social logo

demo-xtweets's Introduction

Xtweets API

Pequeña API para la creación de Post, va orientado al curso de iOS de Platzi, ya que la API original no se encuentra disponible, el código lo puedes encontrar aquí.

API URL

[**https://xtweets-api-dev.webfamous.mx/**](https://xtweets-api-dev.webfamous.mx/)

Register [POST]

https://xtweets-api-dev.webfamous.mx/v1/register/

Enviamos información por Body:

{
    "username": "Demo",
    "email": "[email protected]",
    "password":"passwordDemo"    
}

Por cada registro tenemos como respuesta:

{
    "user": {
        "username": "Demo",
        "email": "[email protected]"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjkxMTg3ODI1LCJpYXQiOjE2OTExODc1MjUsImp0aSI6IjMwMTIzMjVhNGIwYjQ0ODQ4YjA5ODQ4Njg2ZDY2MTY5IiwidXNlcl9pZCI6Mn0.8_dWOyT3qGF0DIoVBs6wIlqnCXbEprRFcy-u2ds5onA"
}

Auth [POST]

https://xtweets-api-dev.webfamous.mx/v1/auth/
{
    'email': '[email protected]',
    'password': 'pepito123',
}

Posibles respuestas de error [Status code 400]:

//Cuando el usuario ya existe
{
    "username": [
        "A user with that username already exists."
    ]
}

//Faltan credenciales
{
    "error": "Missing credentials in JSON data"
}

Consulta de Post [GET]

Se obtienes los post desde la ruta:

https://xtweets-api-dev.webfamous.mx/v1/post/?page=1

Recuerda incluir el token para obtener el listado, si no se envían los accesos tenemos un error como el siguiente:

{
    "detail": "Authentication credentials were not provided."
}

Cuando enviamos el token correctamente obtenemos:

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "content": "Mi second post",
            "location": null,
            "imageUri": null,
            "videoUri": null,
            "author": {
                "username": "Erix",
                "email": "[email protected]",
                "first_name": ""
            },
            "uuid": "4195f0d2-7a60-4af7-986b-e38eb3d829f2",
            "created": "2023-08-04T22:24:50.686768Z",
            "updated": "2023-08-04T22:24:50.686790Z"
        },
        {
            "content": "Mi first post",
            "location": null,
            "imageUri": null,
            "videoUri": null,
            "author": {
                "username": "Erix",
                "email": "[email protected]",
                "first_name": ""
            },
            "uuid": "7bb27f3b-4173-44af-a14c-4d45606118e6",
            "created": "2023-08-04T22:24:33.085583Z",
            "updated": "2023-08-04T22:24:33.085603Z"
        }
    ]
}

A diferencia de la API original, se agrega paginado para hacerlo mas parecido a casos reales.

Crear Registro [POST]

Para crear un registro es necesario el campo “content”, los campos opcionales son “location”, “imageUri” y “videoUri”.

https://xtweets-api-dev.webfamous.mx/v1/post/

Información en body:

//Case simple post
{
    "content": "Mi second post"
}

//Case with image
{
    "content": "Hola mundo!",
    "imageUri": "https://images.unsplash.com/photo-1542596594-649edbc13630?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=987&q=80,"
}

//Case with location
{
    "content": "Hola mundo!",
    "imageUri": "https://images.unsplash.com/photo-1542596594-649edbc13630?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=987&q=80,",
    "location": {
        "latitude": "0.000",
        "longitude": "0.000"
    }
}

Respuesta de registro:

//Simple post with image
{
    "content": "Hola mundo!",
    "location": null,
    "imageUri": "https://images.unsplash.com/photo-1542596594-649edbc13630?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=987&q=80,",
    "videoUri": null,
    "author": {
        "username": "Demo",
        "email": "[email protected]"
    },
    "uuid": "5d19afae-16fb-4733-baaa-9cd0238d0c0f",
    "created": "2023-08-04T22:32:40.802960Z",
    "updated": "2023-08-04T22:32:40.802983Z"
}

//Post with location
{
    "content": "Hola mundo!",
    "location": {
        "latitude": "0.000000",
        "longitude": "0.000000"
    },
    "imageUri": "https://images.unsplash.com/photo-1542596594-649edbc13630?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=987&q=80,",
    "videoUri": null,
    "author": {
        "username": "Erix",
        "email": "[email protected]",
        "first_name": ""
    },
    "uuid": "a4524ccb-e30e-47e0-a5a1-67f44029383d",
    "created": "2023-08-04T22:34:52.889318Z",
    "updated": "2023-08-04T22:34:53.026451Z"
}

Borrar Registros [DELETE]

Importante usando método delete podemos eliminar un elemento de nuestra autoría haciendo un request como el siguiente ejemplo:

//Format 
https://xtweets-api-dev.webfamous.mx/v1/post/{uuid}/

//Sample
https://xtweets-api-dev.webfamous.mx/v1/post/a4524ccb-e30e-47e0-a5a1-67f44029383d/

Espero les pueda ayudar para realizar su practica, cualquier duda o comentario quedo a sus ordenes Twitter, Linkedin.

Si gustan agregar cosas, seria increíble. 🔥

Mucho éxito, saludos cordiales. ☺️

demo-xtweets's People

Contributors

erix-mx avatar

Stargazers

Manuel Crovetto avatar  avatar

Watchers

 avatar

demo-xtweets's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.