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
 
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
 
hrushikesh41 profile image
Hrushikesh Kokardekar

Good Work Shreyas and I find this very informative

Collapse
 
shreyazz profile image
Shreyas Pahune

Thanks bro

Collapse
 
ahmedsouidi profile image
Ahmedsouidi

Thanks, very nice post.

Collapse
 
shreyazz profile image
Shreyas Pahune

Thanks bro

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

Very useful!!
Thanks for sharing :)

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

Collapse
 
mdmyr profile image
YuvaRaj Raghunapu

Thanks for sharing