REST Api vs database

LoveToCode 161 Reputation points
2021-05-07T17:35:27.22+00:00

Hi, I would like to know which is the most efficient or best practice used to migrate data - the database or using the REST Api.

Thanks,

Developer technologies | VB
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Albert Kallal 5,586 Reputation points
    2021-05-07T23:47:01.803+00:00

    A REST API has very little to do in the context of migration of say tables from a database.

    REST is really just a simple process in which you expose a URL in the web site that has some function or process that you wish to run on the web server from the client side browser. As such, there not really much of a relevant context or narrative of using REST and data migration in the same context.

    In most cases, you migrate your data by several means.

    One approach is to transfer the database file(s) to the web server, and then say attach that database file to the sql server you using.

    Some cases, you can export the database data as say csv files, and then on web server side, you often have some database import utilities that allow you to import the data.

    In some cases, you can script out the database + data with scripting tools. You then FTP or upload that sql script to the web server, and then run that script on the web server.

    So the concept, the approach, and how you migrate database information usually has rather little to do with REST.

    Now, once you have the data moved up to the web server and connected up to the database system?

    Then sure, at that point, you can create some REST methods to pull data from the database, and you can create some REST methods to insert or update data in the database.

    So, the concept of updating data in the database? Sure, REST methods can be created by you for this purpose.

    But, a data migration? No, you not use REST to achieve this goal. In fact, the transfer of the database information should and will in most cases occur BEFORE you start coding up some REST methods that you need and want for your given application.

    So, REST is just a means for you to expose server side (web site) code and methods to the client side code (JavaScript running in the browser client side).

    Thus, migration of data? Tends to be quite a separate topic. Now it is possible that you wanting to use say some pre-existing web site and service. And they may very well provide some REST calls that allows you to up-load or transfer data. But in most cases, a database transfer of information is not done nor achieved by using REST calls.

    You are certainly free to code up some REST methods on that web site, and use those REST methods to transfer data. However, in most cases, you not need nor use nor require to code up some REST methods on that site to help you transfer the data. You could perhaps write and create some REST methods to help you transfer of such data – but in most cases, you have quite a few options to transfer such data – and do so without you having to create some REST methods on that site for this purpose.

    I would thus only suggest to use REST to transfer your database and information to a web site WHEN the web site hosting already has a bunch of REST methods pre-built for you. In that case, then sure – write and use some client side software to transfer data.

    But in the context of a database migration project? You building and writing some REST methods on the web site side of things is not a typical approach. I suppose if that web site did not provide any other means to migrate and up-load database information, then I suppose as a last resort, you could then as noted code up some REST methods to help you in this process – but it certainly not the normal approach here.

    Regards,
    Albert D. Kallal (Access MVP 2003-2017)
    Edmonton, Alberta Canada

    1 person found this answer helpful.
    0 comments No comments

  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-05-08T01:57:28.577+00:00

    If you are working with .NET Core 5 and ASP.NET Core and not in a hurry consider checking out ASP.NET Core and the up coming Entity Framework Core for VB.NET along with OWIN.

    Imports System.Collections.Generic  
    Imports System.Web.Http  
      
    Namespace OwinSelfhostSample  
    	Public Class ValuesController  
    		Inherits ApiController  
      
    		' GET api/values   
    		Public Function [Get]() As IEnumerable(Of String)  
    			Return New String() { "value1", "value2" }  
    		End Function  
      
    		' GET api/values/5   
    		Public Function [Get](ByVal id As Integer) As String  
    			Return "value"  
    		End Function  
      
    		' POST api/values   
    		Public Sub Post(<FromBody> ByVal value As String)  
    		End Sub  
      
    		' PUT api/values/5   
    		Public Sub Put(ByVal id As Integer, <FromBody> ByVal value As String)  
    		End Sub  
      
    		' DELETE api/values/5   
    		Public Sub Delete(ByVal id As Integer)  
    		End Sub  
    	End Class  
    End Namespace  
    
    1 person found this answer helpful.
    0 comments No comments

  3. Duane Arnold 3,216 Reputation points
    2021-05-08T09:17:27.94+00:00

    A Restful API is in essence is a Web service that is using Json or XML as the data exchange between the Restful API client and the Restful API service. A Restful service is used to do CRUD operations with a database on the behalf the the Restful client in most cases.

    You want to migrate a database, then IMHO you use traditional DBA tools.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.