Home > Web Front-end > JS Tutorial > Backend Straight #2

Backend Straight #2

Mary-Kate Olsen
Release: 2024-10-07 06:19:01
Original
426 people have browsed it

Reto de backend #2

Welcome to the second post in this series of backend challenges.

In the first challenge we face creating an API without a database connection. This time we will increase the difficulty a little.

Endpoint API with connection to SQL database

Project description

We need to keep track of the weight of a client named Ramon, so for that we need to create a system with the following.

Requirements

  • Save the following weight format

{
  "weight": 125.5,
  "date": "2024-02-12"
}


Copy after login
  • Save the information in a SQLite database (At the end you can find the syntax to create the weight table)
  • The api should have only one endpoint with the name weights
  • You can update, delete, create and read weight data
  • Send an id in the json when deleting or updating

Starting point

The routes should be like the following


GET localhost/api/weights

POST localhost/api/weights

PUT localhost/api/weights

DELETE localhost/api/weights


Copy after login

In the delete and put method you need to pass an id inside the body of the json to delete or update.

SQL for the project

Weight table


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



Copy after login

The above is the detailed content of Backend Straight #2. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template