DEV Community

Carlos Estrada
Carlos Estrada

Posted on

Reto de backend #2

Bienvenido al segundo post de esta serie de retos de backend.

En el primer reto nos enfrentamos a crear un api sin conexion a base de datos. En esta ocasion subiremos un poco la dificultad.

Api endpoint con conexion a base de datos sql

Descripcion del proyecto

Necesitamos llevar un registro del peso de un cliente llamado Ramon, entonces para eso necesitamos crear un sistema con lo siguiente.

Requisitos

  • Guardar el siguiente formato del peso
{
  "weight": 125.5,
  "date": "2024-02-12"
}
Enter fullscreen mode Exit fullscreen mode
  • Guardar la informacion en una base de datos sqlite (Al final puedes encontrar la sintaxis para crear la tabla de pesos)
  • La api debera tener solo un endpoint con el nombre de weights
  • Puede actualizar, eliminar, crear y leer la data de los pesos
  • Envia un id en el json cuando sea eliminar o actualizar

Punto de inicio

Las rutas deberian ser como las siguientes

GET localhost/api/weights

POST localhost/api/weights

PUT localhost/api/weights

DELETE localhost/api/weights
Enter fullscreen mode Exit fullscreen mode

En el metodo delete y put necesitas pasar un id dentro del body del json para eliminar o actualizar.

SQL para el proyecto

Tabla de pesos

CREATE TABLE weights (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  weight DOUBLE,
  weight_date DATE
);

Enter fullscreen mode Exit fullscreen mode

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay