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
 
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.

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
 
lakiramd profile image
Lakira Minlaka β€’

great jobπŸ‘πŸ€Ÿ

Collapse
 
shreyazz profile image
Shreyas Pahune β€’

Thanks

Collapse
 
ahmedsouidi profile image
Ahmedsouidi β€’

Thanks, very nice post.

Collapse
 
shreyazz profile image
Shreyas Pahune β€’

Thanks bro

Collapse
 
mdmyr profile image
YuvaRaj Raghunapu β€’

Thanks for sharing

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
 
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
 
tanwi2209 profile image
Tanwi Kumari β€’

Very useful!!
Thanks for sharing :)

Collapse
 
shubhampatilsd profile image
Shubham Patil β€’

Sweet and simple Express. Awesome!

Collapse
 
shreyazz profile image
Shreyas Pahune β€’

Thanks πŸ˜πŸ’―

Collapse
 
raqibnur profile image
Raqib Nur β€’

Thanks a lot very helpful article

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
 
disjohndoe profile image
disjohndoe β€’

Very clean and simple. Thank you.

Collapse
 
johntarus profile image
johntarus β€’

Short and precise!