Hello everyone,
I am new to RESTful API. I have a task to create an API to update my database. Do I need to create the whole CRUD or I can simply create a PUT immediately. I have an existing database, do I need to do migration?
Thanks for the reply.
Hello everyone,
I am new to RESTful API. I have a task to create an API to update my database. Do I need to create the whole CRUD or I can simply create a PUT immediately. I have an existing database, do I need to do migration?
Thanks for the reply.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Oct 6, 2023, 5:35 AM EDT
When creating a RESTful API to update your database, whether you need to implement the entire CRUD (Create, Read, Update, Delete) functionality or just a specific HTTP method like PUT depends on your application's requirements.
Here's a breakdown of your options:
Create a Specific Endpoint for Updates (e.g., PUT):
Implement Full CRUD Functionality:
Regarding database migration:
In summary, you can start by implementing a PUT endpoint if your primary goal is to update existing data.
Sachin SinghRank #66 · 26.2K reputationPosted Oct 6, 2023, 11:24 AM EDT
No, atleast you should create Find/GetByID and Update/Patch methods.
Follwo my article on these to understand real meaning of Rest API
https://www.sharpencode.com/article/WebApi/implementing-crud
Ajay KumarRank #56 · 29K reputationPosted Oct 6, 2023, 5:44 AM EDT
reating a RESTful API involves designing endpoints to perform various operations on your database. RESTful APIs typically follow the CRUD (Create, Read, Update, Delete) operations, where you can create new records, read existing records, update records, and delete records. However, you are not obligated to implement all CRUD operations for every resource in your API. The specific operations you implement depend on your application's requirements.
Regarding your specific situation:
Creating a PUT endpoint: You can start by creating a
PUTendpoint to update existing records in your database. This endpoint would be responsible for updating specific resources identified by their unique IDs. If updating resources is the only functionality you need for now, you can focus on implementing thePUTmethod.Example endpoint:
2. Database Migration: If you have an existing database schema and you're making changes to it (such as adding new columns, modifying existing columns, etc.), you might need to perform database migration. Database migration is the process of updating your existing database schema to a new version without losing existing data. The specific steps for migration depend on the database system you're using.
If you're using an ORM (Object-Relational Mapping) framework like Django ORM for Python, Sequelize for Node.js, or Entity Framework for .NET, these frameworks often provide tools to handle database migrations. If you're working with raw SQL or a NoSQL database, you'll need to write migration scripts manually to update the schema.
In summary, you can start by creating a
PUTendpoint to update records in your existing database. If you need to modify the database schema, you should plan and execute the migration process to ensure your existing data is not lost or corrupted during the update.Tahir AnsariRank #366 · 6.8K reputationPosted Oct 6, 2023, 10:58 AM EDT
Whether or not you need to create the whole CRUD or simply create a PUT depends on your specific needs. If you only need to update your database, then you can simply create a PUT endpoint. However, if you need to create, read, or delete data from your database, then you will need to create the whole CRUD.
Whether or not you need to do a migration depends on your database and the changes that you are making to the database schema. If you are changing the database schema, then you will need to do a migration. However, if you are simply updating the data in your database, then you may not need to do a migration.
To determine whether or not you need to do a migration, you can use the following steps:
If you are not sure whether or not you need to do a migration, you can consult with a database administrator.
some additional things to consider:
Jes SieRank #1,285 · 1.3K reputationPosted Oct 7, 2023, 8:25 AM EDT
Thank you so much for all your replies. It helps me understand what to do next.