Tag Archives: REST API

Building A NodeJS Based REST API Using Mongoose Node Module


Building A Node.js Based REST API Using Mongoose Node Module
// C-Sharpcorner Latest Articles

In this article you will learn how to build Node.js based REST API using Mongoose Node Module.

New Release of Aspose.Pdf Cloud SDK for Python – A Complete Solution to Manipulate PDF Portab le Document Format in Python Using Powerful Aspose.Pdf Cloud APIs


New Release of Aspose.Pdf Cloud SDK for Python – A Complete Solution to Manipulate PDF Portable Document Format in Python Using Powerful Aspose.Pdf Cloud APIs
// Blogs – Aspose.com

Aspose.Pdf for Cloud

aspose pdf for cloud 140px New Release of Aspose.Pdf Cloud SDK for Python – A Complete Solution to Manipulate PDF Portable Document Format in Python Using Powerful Aspose.Pdf Cloud APIsAspose.Pdf for Cloud’s platform independent document manipulation API is a true REST API that can be used with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more. You can use it with any platform — web, desktop, mobile, and cloud.

With Aspose.Pdf for Cloud you can work with all aspects of PDF (portable document format) file: read, write, convert, split, merge and many more options to manipulate PDF documents. Aspose.Pdf for Cloud is a complete solution for performing any manipulation you can wish to perform on PDF files in the cloud. Learn More

Building REST API for Legacy PHP Projects


Building REST API for Legacy PHP Projects
// Toptal Engineering Blog

Every once in a while PHP developers are charged with tasks that require them to extend the functionalities of legacy projects, a task that often includes building REST APIs. Building a REST API for PHP-based projects is challenging, but in the absence of proper frameworks and tools, it can also be a particularly difficult goal to get right. In this article, Toptal engineer Arminas Zukauskas shares his advice, with sample code, on how to build a modern structured REST API around existing legacy PHP projects.

Mastering Your Inbox with the Gmail JavaScript API


Mastering Your Inbox with the Gmail JavaScript API
// SitePoint

In this article, we’re going to build a basic Gmail inbox and message viewing app using the Gmail RESTful API. The purpose of this article is to give you a good starting point to create cool new JavaScript apps of your own using this API. We’re going to use jQuery and Bootstrap to take some weight out of the code base so we can focus on getting something working quickly without worrying about cross-browser JavaScript inconsistencies and basic styling.

As ever the complete code for this article can be found on our GitHub repo.

Gmail Logo

Enabling the Gmail API on Your Google Account

First off, we need to enable Gmail API access to get our API credentials. To do this, we need to visit Google’s Developer Console in our favourite web browser. From there, we need to create a project (or choose an existing one) and go to the APIs section. Choose “Gmail API” under the Google Apps APIs section and click the “Enable API” button.

Now we need to create two sets of credentials, one for an OAuth 2.0 client ID for a web application and the other to create a browser API key. This can be done in the credentials section of the Google Developer Console by clicking the “Add Credentials” button.

Add credentials screenshot

For the browser API key we need to only fill in the “name” field. However, for production I’d recommend adding a HTTP referrer (this will prevent abuse of our API key from non-authorized domains). For the OAuth 2.0 client ID we must enter at least one authorized JavaScript origin. For a local development environment this will likely be http://localhost or similar. We do not need to enter an authorized redirect URI.

Once we’ve filled in the necessary fields we should be able to see our credentials back in the Credentials section. Keep this info open in a browser tab for later.

Connecting to the Gmail API

[author_more]

Even though the Gmail API is a standard REST API using OAuth 2.0 we recommend using Google’s own JavaScript libraries for connecting to and working with any Google-authored APIs. This is because Google has already packaged up authentication logic and the required dependencies into a single include file — less work for us!

So, first things first – let’s set up our HTML file which we’re going to use as the base of our app. For the purpose of this app we’re going to include all of our code in a single HTML file. In a production environment Id recommend splitting out HTML, CSS and JavaScript into separate files.

<!doctype html> <html> <head> <title>Gmail API demo</title> <meta charset="UTF-8"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> <style> .hidden{ display: none; } </style> </head> <body>

Gmail API demo

Authorize

//ahref= //ahref= var clientId = ‘xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com‘; var apiKey = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’; var scopes = ‘https://www.googleapis.com/auth/gmail.readonly’; http://ahref= </body> </html>

Right at the bottom (above the closing </body> tag) is where we include Google’s JavaScript client library. Notice the query string on the end, this contains the callback function which will be executed once the script has loaded — we’ll use that to initialize our app a little later. Just above that is where we are defining our API credentials, we need to paste these from the Google Developer Console Credentials section. We also define which permissions we’ll require from the user, these are known as scopes. For the purpose of this app we only require read-only Gmail access. It’s good practice to request as few permissions as possible from the user — this provides the user peace of mind that we’re not going to do something nefarious like send emails on their behalf without them knowing.

Other than that we’ve got a button which will allow the user to authorize us to access their Gmail account, and we’ve also stubbed out a table to hold our inbox data once we fetch it. And, as mentioned earlier, we’ve included the necessary files for jQuery and Bootstrap.

Authenticating the User

Now we’re going to provide a mechanism for the user to authenticate us to access their Gmail account. As mentioned above, we need to build out a function named handleClientLoad() which will automatically be called once Google’s JavaScript client library has loaded into the page. This function will then call a chain of other functions which will eventually lead us to fetching their inbox.

function handleClientLoad() { gapi.client.setApiKey(apiKey); window.setTimeout(checkAuth, 1); } function checkAuth() { gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: true }, handleAuthResult); } function handleAuthClick() { gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: false }, handleAuthResult); return false; } function handleAuthResult(authResult) { if(authResult && !authResult.error) { loadGmailApi(); $('#authorize-button').remove(); $('.table-inbox').removeClass("hidden"); } else { $('#authorize-button').removeClass("hidden"); $('#authorize-button').on('click', function(){ handleAuthClick(); }); } } function loadGmailApi() { gapi.client.load('gmail', 'v1', displayInbox); } 

We should insert this code directly below where we set the API credentials, within the same SCRIPT block.

To summarise the process this chain of function calls goes through:

  1. handleClientLoad() simply sets the API key and passes off to checkAuth() after 1 millisecond.
  2. checkAuth() checks if the user has previously authenticated our app with Google. Setting the immediate parameter to true here means that we do not prompt the user with a login/permissions modal if they are not authenticated. We then pass the authentication result to handleAuthResult().
  3. handleAuthResult() then does one of two things; if the user is already authenticated it’ll load the Gmail API using loadGmailApi(), alternatively it’ll display the authorize button on the UI and attach a click event to it which will trigger handleAuthClick()
  4. handleAuthClick() simply executes the same authentication function as checkAuth() but will present the user with a login/permissions modal. Once the user authenticates the same handleAuthResult() function from before is triggered.
  5. Once those series of functions have been executed and the user has authenticated we should always find ourselves at the loadGmailApi() function. This simply loads the Gmail API functionality from Google’s JavaScript client library and then calls our displayInbox() function.

Continue reading %Mastering Your Inbox with the Gmail JavaScript API%

Part 2: Creating RESTful APIs With NodeJS and MongoDB Tutorial


via Creating RESTful APIs With NodeJS and MongoDB Tutorial (Part II) – Adrian Mejia’s Blog.

Welcome to this RESTful API using Node.js (Express.js) and MongoDB (mongoose) tutorial. You can follow alone to make a stand alone API endpoint, or you could also check out our AngularJS or BackboneJS tutorials to build a javascript-client that connects with the endpoint we are going to built.

Creating a lightweight API wrapper with Refit


via Creating a lightweight API wrapper with Refit | Jerrie Pelser.

With the explosion of web APIs it becomes much more common for applications to integrate in some fashion with external APIs. These APIs are typically RESTful APIs, and normally there will be an official wrapper available for a wide range of programming languages and platforms to allow other developers to more easily integrate with the API.

Sometimes however this may not be the case. It may be that the service in question simply do not see providing a .NET API wrapper as a priority, or that the official wrapper may be targeting the full .NET Framework, and you may be looking for something that you can use from WinRT, Xamarin or PCL libraries in general.

It may also be that you simply do not want to include a large external dependency in your application, or you may actually need an API wrapper for one of your own APIs.

In all of these cases you may be required (or tempted) to write you own wrappers. Writing API wrappers can however be a tedious process.

In these sort of situations I revert to using Refit, which is an open-source PCL library developed by Paul Betts, and it works across just about every flavour of the .NET framework – Xamarin, WinRT, Windows Phone 8, UPW, etc.

Blindsist – Assisting Visually Impaired People using IBM Bluemix Visual Recognition


via Blindsist – Assisting Visually Impaired People using IBM Bluemix Visual Recognition | Abdul Muhaymin – Being Student!.

This blog post will cover how I developed Blindsist app for Xhacknight.

The app was developed using Xamarin.Forms, targeting 3 major platforms (iOS, Android and Windows Phone) same time.

Blindsist is a simple one page application. Objective of the application is taking a photo using Smartphone, The photo is then uploaded to IBM Bluemix using REST Api. IBM Bluemix returns the data in Json format, which will be parsed and spoken out using Native Text to Speech services.

Open a new Xamarin.Forms Portable Class Project.