background preloader


Facebook Twitter

10 Best Practices for Writing Node.js REST APIs | @RisingStack. In this article we cover best practices for writing Node.js REST APIs, including topics like naming your routes, authentication, black-box testing & using proper cache headers for these resources. One of the most popular use-cases for Node.js is to write RESTful APIs using it. Still, while we help our customers to find issues in their applications with Trace, our Node.js monitoring tool we constantly experience that developers have a lot of problems with REST APIs.

I hope these best-practices we use at RisingStack can help: #1 - Use HTTP Methods & API Routes Imagine, that you are building a Node.js RESTful API for creating, updating, retrieving or deleting users. As a best practice, your API routes should always use nouns as resource identifiers. POST /user or PUT /user:/id to create a new user,GET /user to retrieve a list of users,GET /user/:id to retrieve a user,PATCH /user/:id to modify an existing user record,DELETE /user/:id to remove a user. #2 - Use HTTP Status Codes Correctly Restify. RESTful API Designing guidelines — The best practices. Search. Untitled. Examples: Searching Twitter by location and with specific keywords - Thoughtfaucet. This page is part of the Twitter location search resource on Thoughtfaucet which contains tutorials for Tweetdeck and Hootsuite, examples, caveats and how to find latitude and longitude in order to make a geocode.

Here are a selection of Twitter searches by location. Each one has a geocode and map so you know how far it reaches. If you don’t find the search code you need in this reference, leave a comment and let me know what you’re after. I’ll update this reference. Twitter search can filter by the location of a Tweet if the user has location services turned on. If the Twitter user doesn’t have location turned on, Twitter can filter tweets based on the location in a Twitter user’s profile. Additional background on this concept is at the beginning of the online version of my Listening Strategy presentation.

Using geocodes to filter tweets based on location is what locative media geeks refer to as setting up a geofence. Example: Tweets about Hurricane Sandy in Vermont. Twitter-stream-channels. With the Twitter stream API, you can only open one stream at a time. So, if you have multiple filters, the tweets in result will be mixed up, you'll need to do some post-processing. This module lets you open multiple channels with there own filters, on the same stream. And then, you can add events to each of them individually, to listen to there results, like if you had open multiple streams. twitter-stream-channels handles all the post-processing, the connexion layer (OAuth, etc ...) is handled by twit.

You can see Topheman Datavisual which is a project I made, using this module for the Twitter Stream part. Installation Just run npm install twitter-stream-channels Example : file: my.twitter.credentials.json "consumer_key": "XXXXX" "consumer_secret": "XXXXX" "access_token": "XXXXXX" "access_token_secret": "XXXXX" example: var TwitterStreamChannels = ; var credentials = ; var client = credentials; var channels = "languages" : 'javascript''php''java''python''perl' var stream = client; stream var client = Topheman-datavisual.herokuapp. Streaming API request parameters — Twitter Developers.

Use the following request parameters to define what data is returned by the Streaming API endpoints: delimited This parameter may be used on all streaming endpoints, unless explicitly noted. Setting this to the string length indicates that statuses should be delimited in the stream, so that clients know how many bytes to read before the end of the status message. Statuses are represented by a length, in bytes, a newline, and the status text that is exactly length bytes. Note that “keep-alive” newlines may be inserted before each length. As an example, consider this response to a request to The 1953 indicates how many bytes to read off of the stream to get the rest of the Tweet (including \r\n). Stall_warnings Setting this parameter to the string true will cause periodic messages to be delivered if the client is in danger of being disconnected. Such warning messages will look like: filter_level language follow The stream will not contain: track.

Twitter API Tutorial. By Wei Xu (Ohio State University) last updated Feb 28, 2016; originally written July 1, 2015 1. Getting Twitter API keys To start with, you will need to have a Twitter account and obtain credentials (i.e. API key, API secret, Access token and Access token secret) on the Twitter developer site to access the Twitter API, following these steps: Create a Twitter user account if you do not already have one. Go to and log in with your Twitter user account. 2. We will be using a Python library called Python Twitter Tools to connect to Twitter API and downloading the data from Twitter. Download the Python Twitter tools at Install the Python Twitter Tools package by typing in commands: $ python --help $ python build $ python install 3.

The Streaming APIs give access to (usually a sample of) all tweets as they published on Twitter. Basic Uses of Streaming APIs If you run the program by typing in the command: 4. Speed up your RESTful API development in Node.js with Swagger. Free Course Build Your First Node.js Website Node is a powerful tool to get JavaScript on the server. Use Node to build a great website. # Introduction So it happened I started this project with friend of mine, a new app to launch on the mobile market. I offered to write the server-side, a simple web API. Once he got my code he immediately asked me "Sam how do I know the routes and so on?! I presume many of you encountered this situation before or will in the future, a developer may write the best web API service but without proper documentation how can other developers discover and use it?

Swagger offers: Interactive documentation.Discoverability.Client SDK generation. In addition, it is supported by many programming languages. One feature I like is the mock mode, which allows developers to design routes without writing a single line of code in javascript. This is the approach I am going to follow in this tutorial: We first focus on the design and then on the code. Prerequisites N.B. GET /movie.

Speed up your RESTful API development in Node.js with Swagger. Architecting a Secure RESTful Node.js app. In this post, we will take a look at architecting a Node.js app that will act as a REST API server for all of our clients. We will be implementing a Token Based Authentication to authenticate and authorize the client to access the application data. This application design is targeted at systems that would like to implement its own REST API with a custom authentication. To showcase how one can consume the REST API with authentication, we will be writing an Angular.js client.

This post is inspired by Authentication with AngularJS and a Node.js REST api. You can find the completed code here. So, let us get started. If you are new to REST API, I would highly recommend watching the below video Also do checkout and HTTP Status codes for more info. Security If you are new to implementing security or want to gain a fair idea, I would recommend watching the below video Architecture Now the question which arises is how do we know if the client accessing our REST API is genuine?

Login <! How to use APIs with JavaScript. Node.js and Express - Creating a Rest API. Once you learn a little bit of Node.js you find that modules make life much easier. One of the most popular and useful is Express. It carries a lot of similarities to the Ruby framework, Sinatra. This makes it a great tool for building REST APIs. This article will teach how to use Express and build a basic REST API. Installing Express npm Module The first thing we need to do is install the Express module. The first method is updating your package.json file (or creating one) with the dependency for Express. Once the package.json file is updated you'll need to run the npm installation. npm install The second method is useful if you've already got a package.json file.

Npm install express --save The project directory will now have a node_modules folder and inside it will be an express folder. First Application To get rolling let's build a very simple application to get familiar with the syntax of Express. The start of the file needs to include the express module using a require statement. Using Fetch - Web APIs. The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.

This kind of functionality was previously achieved using XMLHttpRequest. Fetch provides a better alternative that can be easily used by other technologies such as Service Workers. Fetch also provides a single logical place to define other HTTP-related concepts such as CORS and extensions to HTTP. The fetch specification differs from jQuery.ajax() in two main ways: The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. A basic fetch request is really simple to set up. Fetch(' .then(function(response) { return response.json(); }) .then(function(myJson) { console.log(JSON.stringify(myJson)); }); Supplying request options Uploading JSON data Body. ProgrammableWeb - APIs, Mashups and the Web as Platform. API Management | Predictive Analytics.

Gmail API. What Is an API, and Why Does It Matter?