This document discusses building APIs for frontend applications. It introduces Robert Ignat, a backend developer who previously worked frontend. It then outlines reasons for and solutions to building APIs, including using Express and faker.js to mock data, and Sails.js to declare data structures. It also advertises a GitHub project called monkepark that demonstrates building a monkey API for frontend applications. The document concludes by inviting questions.
Welcome!
In the next half hour or so I’ll be giving you an introduction to writing APIs in Node.js.
If you haven’t done this before, don’t worry, this presentation is made for people with little to no experience in this subject.
Moving on to the mandatory “who am I” page.
I am Robert and I work as a Backend Developer for Jexia.
I have previously worked as a Frontend Developer, using AngularJS mainly. Did that for a while in Jexia also, but ended up focusing on Backend and APIs.
This is where you can find me. I’m not active on twitter, but if you send me any questions I will reply.
Considering the scope of this meetup, I expect most of you to be frontend developers.
I want to introduce you to backend programming by showing how to relatively simply create something that many of you use all the time: APIs.
More precisely, we are going to mock some APIs.
This technique can be useful if you are waiting for your backend colleagues to finish their part or just want to prototype something. After this presentation you should know at least where to start.
We will begin by discussing some of the decisions regarding the project that we are going to build: monkepark, which is a simple simple webapp with information about some monkeys. Of course, we are only going to mock the backend.
I will then present some solutions, alternatives to easily build APIs and then start writing some code for our monkey api.
In the end, of course, we are going to have a Q&A session.
So let’s see why…
First of all, why Node? Why not PHP, Ruby or anything else? Because it’s JavaScript and it’s probably the easiest way for frontend developers to get into backend programming.
You might also ask “Why Monkeys?” Because Apeldoorn is host to a large monkey park.
When mocking APIs you mainly have 2 options: One is to declare the data structure. I will give you a short example using Sails, which is a node MVC framework (similar to Ruby on Rails or Laravel) that can generate REST APIs from your models. - example
During sails installation: This will install the Sails framework and the CLI which we can use to create new projects or generate various parts of code, like models or controllers.
On `sails lift`: Because sails handles schema migrations as well, we need to tell it what strategy to use. It will ask us now, but it’s easily configurable to avoid doing this on every “lift”.
Another one is to use a smaller framework, like express, and to mock the data yourself. Although the second option needs more code/work, it is more flexible.
Faker.js is a js library that can help “generate massive amounts of fake data” as they say. It is quite easy to use and it can be useful in this case as well, so I recommend that you check that out as well.
An important thing to note is that in the Sails example data will be persisted and will be the same between server restarts, but in the next example (monkepark) data will reset to the original list each time.
To illustrate what I mean, let’s start building an API for our monkeys.
You can find the final version on github along with a step by step guide in the README as well as links to the various tools that we are going to use.
Before we get started, how many of you use Node? If not many, ask about Grunt and Gulp.
I am going to use node v4, but any version greater than 0.12 should work just fine.
There is going to be a Q&A at the end, but if you have any questions, especially related to the code, please just interrupt so you don’t lag behind.
If you are following along and get stuck you can also ask Dennis for help. Dennis!
!! After each step ask if they are ready to move on.
After all is done: If you know what Jexia does you will probably wonder why not use it. It’s because this presentation would last only 2 minutes.