How to use mongoDB with your Lumen API

Rafael Almeida
HackerNoon.com
3 min readFeb 20, 2017

--

I’m currently building a RESTful API using Lumen, from the guys that brought to us Laravel. Lumen is a great micro-framework with most of the spectacular features from Laravel like Eloquent, caching, validation, routing, middleware and so on and so forth. The API I’m building it’s supposed to serve an, yet to develop, iOS app that it’s meant to support the information system of the college where I attend, which don’t correctly support mobile devices.

This would be a pretty straightforward project but unfortunately they won’t make my life easy and won’t let me to access the existing database. It sucks, right? However they have a SOAP Web Service available that I can use. But… If I used their web service alongside my API every time I made a request it would take ages to get the information I’ve requested. This is, obviously, a shitty way to do things. So I’ve decided to implement a database where I can store the data by myself.

I’m fully aware that we shouldn’t repeat data but I can’t find a better way this time. I’ve decided to develop some Python bots that would periodically fetch information using the SOAP web service and store it on the database to be later served using the REST API. I’ve decided to use mongoDB mostly for its flexibility, performance and scalability. I’m using mongo 3.4 so all the commands below are tested for this version.

--

--

Rafael Almeida
HackerNoon.com

Hey! I write about several stuff, mostly technical or software development related, often switching from Portuguese to English.