DEV Community

Beginner's guide to creating an API from scratch using Rails

Lisa Jung on May 10, 2020

So you've got your hands on some sexy data and you are dying to share it with the world. You've decided to build an API but you are just getting fa...
Collapse
 
raj_sekhar profile image
Raj Sekhar

The flow of article and the way things are organized is amazing. I would be keeping this one as a reference, when I would writing one myself.
Adding pics of postman for each of the steps u described would have been icing on the cake.

Collapse
 
lisahjung profile image
Lisa Jung • Edited

Raj!!

Your comment just made my day. Thank you for your amazing suggestion.

That is totally what I wanted to do as well!!

I am a mark up language novice and I couldn't find resources that teach how to insert screenshots into dev.to blog. If you know how, please let me know. I would LOVE to incorporate your suggestion in my next blog.

Thanks again for a great feedback! :)

Collapse
 
krrish96 profile image
Sai Krishna • Edited

Great Article, Lisa!

For adding images to dev.to posts you will have an option to upload images on the edit page.

Image Option

You will have two image types - Cover (for cover image) and Body images (for the post).
Imag upload types

On successful upload you will get markdown and URL for the image - you can use either of them, just copy-paste the markdown ![alt text](url) or copy URL alone add img tag - <img src="url" alt="alt text" />

image url

That's all you need to do for adding images.
P.S. for the cover image you do not need to copy-paste, by default it will be at top of post.

Thread Thread
 
lisahjung profile image
Lisa Jung

Sai!! Why are you so amazing??

I am so excited to apply your advice on my blog posts.

Thank you so much for all the time and effort you've put into giving me great advice.
Your kind words and encouragement inspires me to continue blogging.

Hope you have a great night. You absolutely deserve it!!

Collapse
 
johnkibirige005 profile image
Kibirige John

Wow, this has been so helpful, the ease with which you explain things is so amazing.

Collapse
 
lisahjung profile image
Lisa Jung

Hey @johnkibirige005 ! Thank you so much for your kindest message. You made my day!

Collapse
 
johnkibirige005 profile image
Kibirige John

Thank you Lisa

Collapse
 
lflores1961 profile image
Fernando Flores

A great contribution, thank you Lisa, I wonder how to write this as a Microservices architectured solution, I'll be elaborating on this, thank you again

Collapse
 
badasscoder profile image
Badasscoder

In rails 7 it is 36
gem "rack-cors"

Collapse
 
lisahjung profile image
Lisa Jung

Thank you so much @badasscoder ! Haven't worked with Rails in awhile. Your comment will be so helpful to others who come across this blog. Thank you again! :)

Collapse
 
rajatshahi profile image
RAJAT SHAHI

Can we expect new rails blog from you ??

Collapse
 
lisahjung profile image
Lisa Jung

Hi @rajat Shahi!
I actually don't write about rails anymore and switched my focus to Node.js and Elasticsearch. There are so many great bloggers on Dev.to who write about rails so I would check out the resources as you continue your journey! Thank you again for a great compliment. :)

Collapse
 
rajatshahi profile image
RAJAT SHAHI

This blog was very simple and very informative. thanks :)

Collapse
 
realcorsi profile image
Stefano Corsi

Great post, Lisa, very well organized. Everything worked at first attempt. Few words: thanks.

Collapse
 
lisahjung profile image
Lisa Jung

So glad you found it helpful @stefano Corsi! Thank you for the wonderful comment!

Collapse
 
cah4758 profile image
Charles Hernandez

Thanks for the tutorial! I'm seeing a lot of job posts that involve Ruby on Rails and this was a great intro for me. It's really cool seeing how similar all of these languages can be.

Collapse
 
lisahjung profile image
Lisa Jung

You are so welcome @charles Hernandez! I am so glad you found it helpful! :)

Collapse
 
evieskinner18 profile image
Evie

Sick tutorial thank you so much! I needed a refresher on Rails as haven't practised it in three years. Your article has really helped me regain my confidence cheers Lisa!

Collapse
 
lisahjung profile image
Lisa Jung

@evie !! Thank you so much for your wonderfully uplifting message. I am so glad my blog was helpful!! :))

Collapse
 
k00lgithub profile image
cyberdude

Wow, nice article. I didn't know it's so easy to create an API using RoR. It's basically some sort of headless/faceless app since you don't have to create the views.

Thanks for sharing.

Collapse
 
lisahjung profile image
Lisa Jung

You are so welcome and thank you for the kind words k00Lgithub! Your message put a huge smile on my face. :)))

Collapse
 
donmb1 profile image
Martin Braun

Perfect!
As addition I'd add a note how to secure the API, for example with basic auth: api.rubyonrails.org/classes/Action...

Collapse
 
ashakae profile image
AshakaE

Thanks a whole lot!

Collapse
 
lisahjung profile image
Lisa Jung

You are so welcome @ashakae !

Collapse
 
tcom009 profile image
Gerson Mayer

Totally in love with this article! Accurate and concise!

Collapse
 
lisahjung profile image
Lisa Jung

Thank you so much Gerson!! You made my day!

Collapse
 
heflerdev profile image
Henrique Hefler

Explendid article meu amor!
You surely helped me a lot with some Rails concepts I'm struggling to understand.

Collapse
 
lisahjung profile image
Lisa Jung

Thank you so much @henrique Hefler! You made my day! :)

Collapse
 
enowmbi profile image
Enow B. Mbi

great article. wonderful.Great teacher.

Collapse
 
lisahjung profile image
Lisa Jung

Hi Enow! Your comment put a huge smile on my face. Thank you so much for your wonderful message!! :)))))

Collapse
 
ivanmvh profile image
Ivan Martinez von Halle

Excellent, neat, simple and complete, Thank you.

Collapse
 
fernandoamz profile image
Fernando Amezcua • Edited

Thanks for share this article it is too great. Do you have some way to test the routes with Rspec?

Collapse
 
lisahjung profile image
Lisa Jung

Aw thank you @fernando Amezcua!
Hm... I haven't tried testing routes with Rspec but I did find some resources that talk about it! Hope these help. :)

1) geekhmer.github.io/blog/2014/07/30...
2)stackoverflow.com/questions/201972...

Collapse
 
lisahjung profile image
Lisa Jung

@abdo Amin, thank you so much for your kind words! You put a huge smile on my face!

Collapse
 
phuongzzz profile image
phuongzzz

That's so great tutorial!
But can you share the code colorscheme you use? This look so awesome!

Collapse
 
lisahjung profile image
Lisa Jung • Edited

Thank you so much phuongzzz! I use the built in code colorscheme for Dev.to.
It allows you to add color highlighting for whatever language your code was written in.

All you have to do is to add three backticks on the lines before and after the code block.
To add syntax highlighting, specify the programming language after the first three backticks. I added Ruby after my first three backticks to add syntax highlighting to my code.

Refer to this resource and scroll down to syntax highlighting if you need clarifications!
markdownguide.org/extended-syntax/

Hope this helps. :)