The Simplest backend

Connecting to a database and managing it absolutely not beginner friendly!

Writing your backend
Testing it
Deploying it

and Deploying on the other side requires further knowledge about cloud.

As a backend developer myself who usually writes the b…


This content originally appeared on DEV Community and was authored by S.K.Roshan

Connecting to a database and managing it absolutely not beginner friendly!

  • Writing your backend
  • Testing it
  • Deploying it

and Deploying on the other side requires further knowledge about cloud.

As a backend developer myself who usually writes the backend in python coupled with a micro framework called flask it's quite hard and time consuming to deploy a single letter change I made in script.

But now its not gonna be the same, integrating a backend is simplified to integrating an API!

CSV2API is tiny project that helps noobs to integrate a Database with the beginner knowledge.

Here's how we do it

  • A database as the name suggests we need data, it is usually store in cloud storages. Here it is going to a CSV file that is manually stored in our repository or any other online storage provider.

  • The minimum pre-requisite in a Database is querying and CSV2API supports that.

In this tutorial we will be using this sample dataset, which talks about a list of Doctors and their job in their niche.

So a simple API request to our simplest backend which is already created for us, in python programming language would be:

import requests

url = "https://csv2api1.p.rapidapi.com/api/v1"


headers = {
    'x-rapidapi-host': "csv2api1.p.rapidapi.com",
    'x-rapidapi-key': "YOUR-RAPIDAPI-KEY"
    }

querystring = {"url":"https://raw.githubusercontent.com/dev-Roshan-lab/healthcare/main/data.csv"}


response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

Output:

{"results":[{" meet_id":" null"," tags":"Throat problem*Ear problem*Ear Nose Throat Diseases*Microscopic Ear Surgery*Endoscopic Nose & Paranasal Sinus Surgery ( Fess)*Microscopic Laryngoscopic Surgery*Sleep Disorders*Hearing Aids*Sinus Surgery*Ear Infection","description":"Dr. Sanjay Sachdeva is one of the best ENT Surgeons in Delhi with specialization in Otorhinolaryngology. He has a rich experience of 32 years in the field of ENT and Head and Neck Surgery. He is recognized as an expertise in the area of Endoscopic Minimally Invasive Approach for Skull Base Surgery.","goodReviews":79.2,"image":"assets/doctor.png","isfavourite":true,"name":"Dr. Sanjay Sachdeva","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Otolaryngologist"},{" meet_id":" null"," tags":"Cancer treatment*Urological Cancer Surgery","description":"Dr. Gagan Gautam is prominent name in the field of Uro Oncology and Robotic Surgery in India. He is a qualified surgeon who has obtained his specialization degree (MCh) from the prestigious All India Institute of Medical Sciences (AIIMS) and US fellowship in Robotic Uro oncology from University of Chicago a leading cancer center in the world. He specializes in the surgical treatment of prostate kidney bladder and other urinary tract cancers.","goodReviews":93.2,"image":"assets/doctor1.png","isfavourite":false,"name":"Dr. Gagan Gautam","rating":3.5,"satisfaction":89.2,"totalScore":72.2,"type":"Uro - Oncologist"},{" meet_id":" null"," tags":"Spinal Surgeries*Endoscopic Disc surgery*Disc replacement*Endoscopic Cranial Surgery*Brain Tumour Surgery*Minimally Invasive Surgery for Spinal Tumours*Motion preserving surgery","description":"Dr. Bipin Walia is one of the Best Neurosurgeons in New Delhi with more than two decades of vast clinical experience in the field of neuro and spine surgery. Dr. Walia has performed more than 7000 spinal surgeries and has a keen interest in advanced technique - Minimally Invasive Surgery for spinal tumors. He is recognized as a pioneer in endoscopic disc surgery and is an expert in the area of motion preserving surgery disc replacement surgery Image guided surgery endoscopic cranial surgery and brain tumor surgery.","goodReviews":88.2,"image":"assets/doctor3.png","isfavourite":false,"name":"Dr. Bipin S Walia","rating":2.5,"satisfaction":78.2,"totalScore":93.94,"type":"Neurosurgeon"},{" meet_id":" skr-lks-tmo"," tags":"Cavity filling*Root canal*Cosmetic Dentistry","description":"Dr. Surbhi Anand is a practicing Endodontist and Conservative Dentist with over 7 years of experience after procuring the bachelors degree she pursued a masters course in Endodontology specializing in Single sitting Root Canal Treatment cosmetic dentistry and smile makeover. She has been associated as a senior consultant with healthcare setups including Fortis hospital and Columbia Asia Hospital and has a vast consultation base to various reputable dental practices in Delhi/NCR.","goodReviews":12.2,"image":"assets/doctor2.png","isfavourite":true,"name":"Dr. Surbhi Anand","rating":1.5,"satisfaction":84.2,"totalScore":75.2,"type":"Dentist"},{" meet_id":" null"," tags":"Gastrointestinal*Gynae Cancers","description":"Dr. Sandeep Batra is Senior Consultant of Medical Oncology at the Max Super Speciality Hospital New Delhi. His educational qualifications include an MBBS from PGI Rohtak; an MD in Medicine from the same institute; a DNB in Medicine from the National Board of Examinations Delhi; and a PGDMLS from the Symbiosis University Pune. He was also previously a Senior Consultant at the Medical Oncology at Medanta The Medicity Gurgaon. He was also involved in academic activities including training of oncology students and oncology nurses. Dr. Batra has many national and international publications to his name and has also edited various oncology-related chapters in numerous books and online resources.","goodReviews":79.2,"image":"assets/doctor4.png","isfavourite":true,"name":"Dr. Sandeep Batra","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Oncologist"},{" meet_id":" null"," tags":"Movement Disorders with Deep*Brain Stimulation (DBS)*Surgery for Epilepsy*Nerve and Brachial Plexus Surgery*Radiosurgery as well as Cerebrovascular Surgery","description":"Dr. Aditya Gupta is highly knowledgeable and skillful neurosurgeon presently practicing in the World's renowned Artemis Hospital Gurgaon. Cofounded the Institute of Neurosciences at Medanta Hospital. A graduate and topper from All India Institute of Medical Sciences (AIIMS) Dr. Aditya Gupta is an accomplished and experienced neurosurgeon. As a student resident and later Faculty at AIIMS he has won several awards such as the prestigious Sir Dorabji Tata Award. He was Associate Professor of Neurosurgery at AIIMS till late 2009.","goodReviews":79.2,"image":"assets/doctor5.png","isfavourite":true,"name":"Dr. Aditya Gupta","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Neurosurgeon"},{" meet_id":" null"," tags":"Joint Replacement Surgery*Hip Arthroplasty*Knee Revisison surgery*Partial Knee Replaceement*Total Knee Replacement surgery*Trauma Management based on AO Principles","description":"Dr. Sanjeev Kumar Singh Marya is one of the Top Orthopedic Surgeons in India and carries over 35 years of extensive and rich experience in his field of specialization.He is a prominent orthopedic surgeon and is highly acknowledged for performing more than 15000 joint replacements surgeries with over 3500 simultaneous knee replacement and 3000 hip replacement surgeries in his illustrious career.","goodReviews":79.2,"image":"assets/doctor6.png","isfavourite":true,"name":"Dr. SKS Marya","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Orthopaedic surgeon"},{" meet_id":" null"," tags":"Implant Dentistry*Immediate Implants*Management Of Implant Related Complications*Flap Surgeries*Root Coverage Procedures*Alveolar Ridge Augmentation","description":"An ambitious qualified Dentist with excellent organizational and interpersonal skills keen to render quality dental care in progressive dental practice. Dr. Amandeep Dhillon is a practicing Periodontist & Oral Implantologist with over 8 years of experience he graduated with bachelors degree in dental sciences with distinction/honor in the subject of Periodontology and was awarded certificate of merit in oral surgery conservative dentistry oral medicine and also holds a masters degree in Periodontology & Oral Implantology and holds a masters degree in Periodontology & Oral Implantology.","goodReviews":79.2,"image":"assets/doctor7.png","isfavourite":true,"name":"Dr. Amandeep Singh Dhillon","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Dentist"},{" meet_id":" null"," tags":"Lymphoma & Leukemia*Head & Neck and Brain Tumors*Multiple Myeloma*Breast cancer treatment*Lung cancer treatment*Gastrointestinal and Gynecological tumors","description":"Dr. Nidhi Rawal has extensive experience in Pediatric and neonatal echo Transesophageal echocardiography and had been actively involved in the Cath lab interventions at PGI Chandigarh.Dr. Rawal has keen interest in research and has attended various national conferences and CMEs regularly. She has many publications (both national and international) to her credit.","goodReviews":79.2,"image":"assets/doctor10.png","isfavourite":true,"name":"Dr. Nidhi Rawal","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Cardiologist"},{" meet_id":" null"," tags":"Voice disorders*Phonosurgery*Head and Neck Surgery*Lasers*Endoscopic sinus surgery*Sleep medicine sialology*Otology*Skull base surgery*Cochlear implants","description":"Dr. K. K. Handa is a renowned ENT specialist andOtorhinolaryngologist in India with over 27 years of rich clinical experience in this field. He is considered one of the best laryngologist voice surgeon and cochlear implant surgeon along with expertise in laser surgery endoscopic sinus surgery sleep medicine robotic surgery and head and neck surgery.","goodReviews":79.2,"image":"assets/doctor9.png","isfavourite":true,"name":"Dr. K K Handa","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"ENT Specialist"}]}

Such a simple API request can helps us with a JSON string which can further consumed as per the needs.

Let us understand the code:

  • At first we import requests which is used to send API requests.
  • We define required variables to send a GET request. replace YOUR-RAPIDAPI-KEY with the key that you get on signing up for the free API.
  • Then we send a GET request to the API.
    • One that we need to keep in mind is that url parameter in the request URL requires a raw CSV file url unlike the common link to any CSV file in Github.
    • Here's how we get it:

Raw image github

  • Finally we print what requested for!

Querying

Querying is very important in accessing and receiving data, without it might cause numerous troubles when the application is scaled!

  • receiving huge amounts data can make the app slower.
  • Might lead to unwanted expenses in cloud provider.
  • parsing the JSON will get harder.
  • Introducing changes into the data will consume more CPU.
  • Makes it harder for the developer to work on the data.

Luckily we have a support for querying in CSV2API

Here's how we do it

we pass a URL parameter called query, for example in our sample dataset we have columns called name, type, rating, goodReviews, totalScore, satisfaction, isfavourite, image, description

We can query in such a way that we only get the data of a doctor with specific ratingor typeetc.

import requests

url = "https://csv2api1.p.rapidapi.com/api/v1"

querystring = {"url":"https://raw.githubusercontent.com/dev-Roshan-lab/healthcare/main/data.csv","query":"name=='Dr. Sanjay Sachdeva' and rating==4.5"}

headers = {
    'x-rapidapi-host': "csv2api1.p.rapidapi.com",
    'x-rapidapi-key': "YOUR-RAPIDAPI-KEY"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

In the above snippet the query we passed to our database is
&query= name == 'Dr. Sanjay Sachdeva' and rating == 4.5 where we are asking the API to return us the data where there name of the Doctor is Dr. Sanjay Sachdeva and his rating is 4.5.

Output:

{"results":[{" meet_id":" null"," tags":"Throat problem*Ear problem*Ear Nose Throat Diseases*Microscopic Ear Surgery*Endoscopic Nose & Paranasal Sinus Surgery ( Fess)*Microscopic Laryngoscopic Surgery*Sleep Disorders*Hearing Aids*Sinus Surgery*Ear Infection","description":"Dr. Sanjay Sachdeva is one of the best ENT Surgeons in Delhi with specialization in Otorhinolaryngology. He has a rich experience of 32 years in the field of ENT and Head and Neck Surgery. He is recognized as an expertise in the area of Endoscopic Minimally Invasive Approach for Skull Base Surgery.","goodReviews":79.2,"image":"assets/doctor.png","isfavourite":true,"name":"Dr. Sanjay Sachdeva","rating":4.5,"satisfaction":85.2,"totalScore":93.2,"type":"Otolaryngologist"}]}

As we can see the amount just drastically reduced and comprehending is now way easier than before.

Precautions

  • String must be passed under single quotes
  • Boolean must be Capitalized. eg: False is correct false is wrong similarly for True.
  • Integers or Float should be under single quotes or double quotes.

Test the API for further columns and for different data at RapidAPI.

Got doubts or facing errors?
Lemme see what you got, in the Discussions


This content originally appeared on DEV Community and was authored by S.K.Roshan


Print Share Comment Cite Upload Translate Updates
APA

S.K.Roshan | Sciencx (2021-12-31T05:39:28+00:00) The Simplest backend. Retrieved from https://www.scien.cx/2021/12/31/the-simplest-backend/

MLA
" » The Simplest backend." S.K.Roshan | Sciencx - Friday December 31, 2021, https://www.scien.cx/2021/12/31/the-simplest-backend/
HARVARD
S.K.Roshan | Sciencx Friday December 31, 2021 » The Simplest backend., viewed ,<https://www.scien.cx/2021/12/31/the-simplest-backend/>
VANCOUVER
S.K.Roshan | Sciencx - » The Simplest backend. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/31/the-simplest-backend/
CHICAGO
" » The Simplest backend." S.K.Roshan | Sciencx - Accessed . https://www.scien.cx/2021/12/31/the-simplest-backend/
IEEE
" » The Simplest backend." S.K.Roshan | Sciencx [Online]. Available: https://www.scien.cx/2021/12/31/the-simplest-backend/. [Accessed: ]
rf:citation
» The Simplest backend | S.K.Roshan | Sciencx | https://www.scien.cx/2021/12/31/the-simplest-backend/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.