DEV Community

Cover image for Make your own API under 30 lines of code

Make your own API under 30 lines of code

Shreyas Pahune on September 24, 2021

Hey readers šŸ‘‹šŸ», in this blog we are going to discuss about making our own API in just 30 lines of code. Topics Covered : What is an AP...
Collapse
Ā 
roljlevy profile image
Roland •

Hi Shreyas, I enjoyed the article. It was simple and to the point.

For the get request I think it would be better to use .json so that the response renders as JSON, like this:

res.status(200).json(products)

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks for sharing… I didn’t know this!!

Collapse
Ā 
roljlevy profile image
Roland •

you're welcome! Will you update the article?

It's shown here in the docs: expressjs.com/en/api.html#res.json

Thread Thread
Ā 
shreyazz profile image
Shreyas Pahune •

Yup I'll surely add this in it

Thread Thread
Ā 
roljlevy profile image
Roland •

Cool :)

Collapse
Ā 
liyasthomas profile image
Liyas Thomas •

If you'd like to spin up these APIs and test them — try an online API development / testing platform - we're building Hoppscotch.io.

GitHub:

GitHub logo hoppscotch / hoppscotch

šŸ‘½ Open source API development ecosystem https://hoppscotch.io

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Hey I have used this!! Have you guys tied up with Aviyel?

Collapse
Ā 
liyasthomas profile image
Liyas Thomas •

Yes we did. They're doing an amazing job on growing OSS ā¤ļøšŸ’Æ.

Collapse
Ā 
thomasbnt profile image
Thomas Bnt •

Simple, good post šŸ‘šŸ¼

Collapse
Ā 
hrushikesh41 profile image
Hrushikesh Kokardekar •

Good Work Shreyas and I find this very informative

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks bro

Collapse
Ā 
adamgonzls profile image
Adam Gonzales •

When I query the endpoint (random-quote-generator-api.adamgon...) using fetch locally I get an cors error and then if I use mode 'no-cors', I get an opaque response. Is there any way around this? I've been trying to figure this out for several hours.

Collapse
Ā 
mdmyr profile image
YuvaRaj Raghunapu •

Thanks for sharing

Collapse
Ā 
johntarus profile image
johntarus •

Short and precise!

Collapse
Ā 
disjohndoe profile image
disjohndoe •

Very clean and simple. Thank you.

Collapse
Ā 
krishsavani profile image
Krish Savani •

Loved this one! Hoping to use my own API soon.

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

That's awesome!

Collapse
Ā 
lakiramd profile image
Lakira Minlaka •

great jobšŸ‘šŸ¤Ÿ

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks

Collapse
Ā 
tanwi2209 profile image
Tanwi Kumari •

Very useful!!
Thanks for sharing :)

Collapse
Ā 
barungh profile image
Barun Ghosh •

Friend... there is a little typo , 27 x 7, I think it should be 24 x 7

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks a lot, I edited it.

Collapse
Ā 
ahmedsouidi profile image
Ahmedsouidi •

Thanks, very nice post.

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks bro

Collapse
Ā 
anuragdev profile image
Anurag Sharma •

Great work Shreyas , and it is so informative.

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks bro, more informative blogs coming soon!

Collapse
Ā 
marwan01 profile image
Marouen Helali •

Great article to quickly spin up an API to be able to focus more on devops afterwards like containerizing it, deploying it, and then scaling it.

Collapse
Ā 
raqibnur profile image
Raqib Nur •

Thanks a lot very helpful article

Collapse
Ā 
shubhampatilsd profile image
Shubham Patil •

Sweet and simple Express. Awesome!

Collapse
Ā 
shreyazz profile image
Shreyas Pahune •

Thanks šŸ˜šŸ’Æ

Collapse
Ā 
jujasen profile image
Julia Jakobsen •

Hi! Maybe a stupid question, but where do i write the code from step 1? Do i need to create a file? What should the file-structure be? I don't understand :/

Collapse
Ā 
shreyazz profile image
Shreyas Pahune • • Edited

Hey Julia, first of all no quesitons are stupid xD! And you just have to create one file having a .js extension.
Create a file let's say index.js and then write your code in it.