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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Oct 6, 2023, 9:35 AM
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.
Jes SiePosted Oct 7, 2023, 12:25 PM
Thank you so much for all your replies. It helps me understand what to do next.
Sachin SinghPosted Oct 6, 2023, 3:24 PM
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
Tahir AnsariPosted Oct 6, 2023, 2:58 PM
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:
Ajay KumarPosted Oct 6, 2023, 9:44 AM
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.