Skip to Main Content
 

Blog title

From CSV to REST API - In Just One Command

INFO_LIST

  • Author Head Binubuo
  • Category Binubuo API
  • Created Wed, Feb 08 2023
 

blog sections

Did you know that with Binubuo, you can convert your test data in a CSV file into a fully enabled REST API in just one command.

We all know the situation where we are given a csv file with some test data, and what we really need is to use the data inside of our application. If your application is using a REST interface for getting data, we can help you with that using the CSV module of the Binubuo client.

Imagine a CSV file named mycars.csv with some data on a few cars:

Chevrolet Chevelle Malibu;18.0;8;307.0;130.0;3504.;12.0;70;US
Buick Skylark 320;15.0;8;350.0;165.0;3693.;11.5;70;US
Plymouth Satellite;18.0;8;318.0;150.0;3436.;11.0;70;US
AMC Rebel SST;16.0;8;304.0;150.0;3433.;12.0;70;US
Ford Torino;17.0;8;302.0;140.0;3449.;10.5;70;US
Ford Galaxie 500;15.0;8;429.0;198.0;4341.;10.0;70;US
Chevrolet Impala;14.0;8;454.0;220.0;4354.;9.0;70;US
Plymouth Fury iii;14.0;8;440.0;215.0;4312.;8.5;70;US
Pontiac Catalina;14.0;8;455.0;225.0;4425.;10.0;70;US
AMC Ambassador DPL;15.0;8;390.0;190.0;3850.;8.5;70;US
Citroen DS-21 Pallas;0;4;133.0;115.0;3090.;17.5;70;Europe
Chevrolet Chevelle Concours (sw);0;8;350.0;165.0;4142.;11.5;70;US
Ford Torino (sw);0;8;351.0;153.0;4034.;11.0;70;US

If we needed a set of the same data, but maybe hundreds of rows, we could try and do copy&paste, but then data would likely be the same across multiple rows. So instead, let me show you how easy it becomes with Binubuo.

>>> from binubuo import binubuoCSV
>>> myBinu = binubuoCSV('YOUR_APPLICATION_KEY_HERE')
>>> myBinu.dataset_from_csv('mycars.csv')
-> Create template from csv file [mycars.csv].
  -> Sampling data on column [c0].
  -> Sampling data on column [c1].
  -> Sampling data on column [c2].
  -> Sampling data on column [c3].
  -> Sampling data on column [c4].
  -> Sampling data on column [c5].
  -> Sampling data on column [c6].
  -> Sampling data on column [c7].
  -> Sampling data on column [c8].
  -> Template for csv file [mycars.csv] successfully created.
-> Create dataset [mycars].
  -> Dataset [mycars] created successfully.
  -> API endpoint deployed at: https://binubuo.com/api/data/custom/[your_unique_url_path]/mycars

That is how easy it is. We now have a complete REST enabled synthetic dataset deployed and ready to use:

> curl -H @{"x-binubuo-key" = 'YOUR_APPLICATION_KEY_HERE'} -Method GET 'https://binubuo.com/api/data/custom/[your_unique_url_path]/mycars' | Select-Object -Expand Content
[
{
"c0":"AMC Hornet"
,"c1":1
,"c2":8
,"c3":295
,"c4":115
,"c5":2911
,"c6":15.87
,"c7":70
,"c8":"ebaq"
}
,{
"c0":"Datsun 200-SX"
,"c1":1
,"c2":4
,"c3":304
,"c4":115
,"c5":2959
,"c6":10.81
,"c7":70
,"c8":"wm"
}
,{
"c0":"Plymouth \u0027Cuda 340"
,"c1":2
,"c2":7
,"c3":313
,"c4":120
,"c5":2985
,"c6":17.41
,"c7":70
,"c8":"cnxsr"
}
,{
"c0":"Chevrolet Nova Custom"
,"c1":3
,"c2":5
,"c3":322
,"c4":129
,"c5":3066
,"c6":13.03
,"c7":70
,"c8":"vpjv"
}
,{
"c0":"Chevrolet Nova"
,"c1":4
,"c2":7
,"c3":323
,"c4":131
,"c5":3082
,"c6":11.39
,"c7":70
,"c8":"neah"
}
,{
"c0":"AMC Concord"
,"c1":4
,"c2":7
,"c3":340
,"c4":138
,"c5":3155
,"c6":9.65
,"c7":70
,"c8":"ysdb"
}
,{
"c0":"Mercury Capri v6"
,"c1":4
,"c2":4
,"c3":340
,"c4":146
,"c5":3173
,"c6":12.47
,"c7":70
,"c8":"pwsw"
}
,{
"c0":"Chevrolet Impala"
,"c1":5
,"c2":5
,"c3":367
,"c4":146
,"c5":3273
,"c6":12.75
,"c7":70
,"c8":"lk"
}
,{
"c0":"AMC Ambassador DPL"
,"c1":7
,"c2":5
,"c3":377
,"c4":153
,"c5":3356
,"c6":9.05
,"c7":70
,"c8":"jrot"
}
,{
"c0":"Volkswagen Scirocco"
,"c1":8
,"c2":4
,"c3":389
,"c4":157
,"c5":3425
,"c6":15.42
,"c7":70
,"c8":"onx"
}
]

How much data you want is fully up to you. Simply add the parameter rows to change the size of the output:

https://binubuo.com/api/data/custom/[your_unique_url_path]/mycars?rows=500

You can also use the "tag" parameter to get the same data every time you make a request:

curl -H @{"x-binubuo-key" = 'YOUR_APPLICATION_KEY_HERE'} -Method GET 'https://binubuo.com/api/data/custom/128482a3/mycars?rows=3&tag=control' | Select-Object -Expand Content

Now that request will always produce the same result:

[
{
"c0":"Dodge Coronet Custom"
,"c1":1
,"c2":5
,"c3":295
,"c4":115
,"c5":2911
,"c6":10.53
,"c7":70
,"c8":"zgxgu"
}
,{                                                                                                                     
"c0":"Ford Maverick"                                                                                                    
,"c1":1                                                                                                                 
,"c2":5                                                                                                                
,"c3":308
,"c4":118
,"c5":2970
,"c6":16.63
,"c7":70
,"c8":"fvke"
}
,{
"c0":"Plymouth Horizon Miser"
,"c1":1
,"c2":8
,"c3":332
,"c4":122
,"c5":3032
,"c6":14.65
,"c7":70
,"c8":"idhx"
}
]

Since we also create REST endpoints for detailed views and POST/DELETE/UPDATE requests automatically, you can always use the first column as an ID to get detailed single record views:

curl -H @{"x-binubuo-key" = 'YOUR_APPLICATION_KEY_HERE'} -Method GET 'https://binubuo.com/api/data/custom/128482a3/mycars/Ford%20Maverick?rows=3&tag=control' | Select-Object -Expand Content

Which will produce the following result:

{
"c0":"Ford Maverick"
,"c1":1
,"c2":5
,"c3":308
,"c4":118
,"c5":2970
,"c6":16.63
,"c7":70
,"c8":"fvke"
}

Don't have an account yet?

If you don't have an account on Binubuo yet, you can create one real quick. Just click "Prices and Registration" in the top right corner, and you are on your way to create all the synthetic data you could dream about.

Want to see how to get started: Get Started Guide

Get more guides and help from the blog

Youtube Channel

Follow Binubuo on Twitter:


If you already have an account on RapidAPI, you can use your account to access Binubuo

Connect on RapidAPI