loading...

The Untold Secret to SYMFONY REST APIs in Less Than Ten Minutes

bamboriz profile image Techonda ・4 min read

Hello, today I will love to share a very interesting experience I had this year with API Development. Basically it is about how I was able to build a production-ready Symfony REST API with little prior knowledge of the framework.

So I had this project a client wanted me to work on but was very specific about using Symfony. It was a backend API to be used to power a front-end React SPA. Even though I had never worked with Symfony, I felt I could handle it. I did have some experience with CodeIgniter 3 and Slim PHP which I knew I could leverage but I had never built an API before. But I knew I could not let this go – the experience – plus the client was playing really well 😉 . So I got to work …

The Magic of Books

“Books are a uniquely portable magic.” ― Stephen King

I needed some magic. I had to build not just an API but a good one. And yes, I am one of those who believe in doing work only if you can get well done. So I turned to books. The first that crossed my mind was Philip Sturgeon’s BUILDING APIs YOU WON’T HATE. A friend had once recommended it but I didn’t need it at the time.

I grabbed the book and finished it in no time. And what I really loved was how the book demystified the whole thing for me. In his book, Philp really makes it fun and I immediately began feeling very confident after just knowing all these new concepts. I then went further to read another book – UNDISTURBED REST by Michael Stowe. After those two, I literally felt APIs run the world.

SYMFONY REST APIs: A First Try

I was now ready to get my hands. But first I had to learn Symfony.

I watched YouTube videos and took some courses but the best by far was the Stellar Development with Symfony 4 course on SymfonyCasts. If you are like me and really new to Symfony like I was, SymfonyCasts is the place you should go to. Symfony 4 is very interesting and when I found out that most of the cool stuff came in Version 4, I was so happy I had never tried Symfony before that 😊 . Once the fundamentals were in place I had to start seeing how to bring in the whole API stuff into the show. That’s when I came across FOSRESTBundle and API Platform. And now there was a dilemma!

FOSRESTBundle VS API Platform

There are a lot of articles and posts all over about this so I am going to rant about which is better but rather what worked for me. So I read all the comparisons I could find and decided to try the two out for myself. I first built a simple API in Symfony (no tools) which was really cool and simple. I then tried doing the same with FOSRESTBundle but found it a bit tricky and I spent a lot of time trying to figure out how to make it work. It made the process easier but I probably did not feel the ease like I would have loved to.

At that point, I was already wanting to build the API with Symfony (no tools) but then I gave API Platform a try and sincerely, I was blown away !

So there I was, excited about this new discovery which made building an API – So Super Easy. It was too good to be true so I got did a lot of research and a very good article I read was one by Marek Gajda – Practical guide to API Platform: How to tell if it’s the right framework for you. And then I decided API Platform was the guy for my SYMFONY REST API.

Conclusion

To keep it really brief API platform is a framework built on Symfony that speeds up the development RESTful APIs. It is based upon best practices and focuses on not reinventing the wheel when it comes to API Development.

SYMFONY REST APIs with API Platform are definitely worth considering for any small, medium or large scale projects. Although far from perfect I just really believe in the project and the team. They do a great job to fix issues and respond to questions on their Slack channel. That’s what enabled me to complete my first project and to build a production-ready RESTFUL API with little prior experience in Symfony.

I would be putting up a full post on my blog on some challenges I faced with API Platform (and still face now), some tips on how to get through them and how I went to complete the API and host it on AWS Elastic Beanstalk.

Do leave any questions you have and if you have any experience with API platform, I will love to hear it.

Thanks!

Posted on by:

bamboriz profile

Techonda

@bamboriz

Love building web & mobile apps and committed to making Tech accessible to all.

Discussion

pic
Editor guide