Writing Testable HTTP APIs Using Node.js - The Basics - Blog. July 15, 2014 - by Gergely Nemeth, RisingStack Share: I remember writing my first test cases - it was everything but nice and clean.
Testing done right is not easy. It is not just about how you write your tests, but also how you design your entire codebase. This post intends to give an insight on how we develop testable HTTP APIs at RisingStack. All the examples use Joyent's restify framework, and can be found at RisingStack's Github page. Setting up your test environment In order to run our test cases, we need a test runner and an assertion library. But enough of the theory, let's setup our test runner and assertion library! Adding mocha to your project npm install mocha --save-dev mkdir test It will install mocha and put it as a development dependency to your package.json. Also, it is convenient to put it into your package.json's scripts section, so it can be run using the npm test command. Adding chai to your project npm install chai --save-dev The above test can be run with npm test.
Next up. Rendering on the Server and Client in Node.js - Artsy Engineering. At Artsy we’ve been building Node.js applications that share code and rendering between the server and browser.
Growing Pains Artsy started as a mostly standard Rails app almost three years ago. We knew we were outgrowing this monolithic project because we had some clear problems… Slow initial page loads because of lacking server-side rendering. How I used node-cache to speed up external API calls. Developer News is a new project I've been working on recently to aggregate and build a JSON API of HackerNews and Reddit/r/programming data sorted by score to produce a list of the currently most popular developer news articles trending on the web.
The API does nothing fancy, it's a Node.js server which calls the Reddit and HackerNews APIs and passes the data returned through a series of filters to sort and sanitise it into something more consumable to a client. Upon initial release, every request to the API would send subsequent requests to the HackerNews and Reddit APIs, resulting in the overall HTTP call to be around 1-2 seconds, which when consumed via a web interface, feels extremely slow. Http - Calling a JSON API with Node.js. Using Node.js to connect to a REST API. Calling a REST API from a NodeJS Script. Lately I have been experimenting with using NodeJS as a scripting language for personal tasks, rather than its typical function as a web server.
There are many things about NodeJS that I like, and writing these little disposable scripts has been a great way to experiment. Recently I wanted to perform some batch operations with my content on The Game Crafter's web service. The Game Crafter provides a full REST API, so this was a clear way to add some automation to my life. In particular, the service requires that its users approve each card in a deck before it is sent to the printer. This is a reasonable requirement, but for people like me who automate the creation of their graphics, it's a lot of manual clicking to go through each card in turn and approve it. For a start, in this article I'll talk about how I used NodeJS to retrieve a listing of card objects for the deck using the REST API.
Making REST calls This is where the data is encoded. Then, we need to set up the HTTPS request. 30+ ways to make REST calls in Node.js, PHP, Python, Rails, Obj-C, .NET, and Java / Android - Mashape Blog.