Community Recurse, Day 1

natalie olivo
3 min readAug 12, 2019

The vibe of this community from the beginning was incredible as you can imagine. A room full of creative types excited to build and learn together. After a shady sushi experience at Trader Joe’s I decided to put my lunch woes behind me and get down into coding. 100 lines of code a day is the kind of productivity I was hoping for. To begin my journey I set out to build an API in Node.

I started out by reading a few articles on best practices. In particular I looked at general advice on how to construct a rest API, and a few reference / tutorials that provided instructions on where to start. I was really eager to code on my first day so I didn’t dive too deep in the reading. Here are some references I started with:

https://medium.com/hashmapinc/rest-good-practices-for-api-design-881439796dc9

https://auth0.com/blog/node-js-and-express-tutorial-building-and-securing-restful-apis/

https://www.toptal.com/nodejs/secure-rest-api-in-nodejs

From my reading I knew a good place to start would be to have an endpoint for each HTTP action/operation and associated schemas for those resources. The articles were sufficient enough to help me solidify some concepts I had superficially understood but needed more concrete practice in such as setting up routes for each resource and ensuring my responses had the expected integrity based on REST architecture and HTTP protocols.

I didn’t want to ruminate too much on what to build so I got excited about building a music app that would suggest music listens based on user behavior and preferences. My resource list would look something like this:

POST /users

/songs

/sounds

/listens

/recents

/auth

I decided to start with one resource (user) and define the basic structure for that user. Here’s what I came up with. (Essentially copied from the toptal article):

id (an auto generated UUID)

firstName

lastName

email

password

permissionLevel

I used Mongoose as a data modeling library and this allowed me with just few lines of code to build out my schema and model. (Note: Being as my journey is really to understand the different parts of what I am building in depth, I’ll be exploring what is under the hood of mongoose in future blog posts.)

I was able to move along pretty quickly creating routes and my first model, controller and schema for my new API.

I spent a good amount of time figuring out how to parse the request response containing the proper HTTP code (For POST the success code would be 201, for failure it would be 4xx). I realized I didn’t know how to parse the body of an https response properly, so I spent a bit of time figuring out how to work with that both the node and express framework way.

I got a bit tangled up in node native boiler plate code vs express code for running the server and handling requests. I realized its probably a good idea to start with one instead of adding layers of complexity. I decided to go with express code since thats what was referenced in the tutorial I was using and promised to rewrite it later for learning purposes.

So as you can tell, I’ve learned quite a bit in just a couple of hours.

I learned (this is honestly an everyday learning in my practice as an engineer) that you can easily add on layers of complexity to your work efforts while using various abstractions and dependencies you are not readily familiar with.

Stay tuned to learn what day two is like returning API response and actually updating models and inserting them into a data store. Ultimately I hope to tie the app I’m building from front to back into a machine learning engine. I hear Sagemaker may be a great place to start !

--

--