Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Michael Mikowski:
RESTful APIs, the big lie
Sep 09, 2015 @ 11:19:31

Michael Mikowski has a post to his site that suggests that a RESTful API is a big lie and that the concept should "rest in piece" and be replaced with something he calls a "JSON-pure API".

If you have read an internet developer resume or job posting in the past 10 years, then you might be forgiven if you think that RESTful APIs are gifts bestowed from the heavens by The One True Web Developer Deity. RESTful APIs are everywhere. Even the marketing folks are pushing them in sales material intended for CEOs and Human Resources-type folks. So how good of an idea are RESTful APIs really?

He starts with a look at where the concepts for a RESTful API originally came from and defines some of the most common concepts around them (verbs, request/response, etc). He then suggests that they're "pretty awful" and lists some of the larger problems he sees with them:

  • Problem #1: There is little agreement on what a RESTful API is
  • Problem #2: The REST vocabulary is not fully supported
  • Problem #3: The REST vocabulary is not rich enough for APIs
  • Problem #4: RESTful APIs are very hard to debug
  • Problem #5: RESTful APIs are usually tied to HTTP

He suggests that the way to move forward is to migrate to the "JSON-pure API" methodology, fixing most of the problems he listed. He describes this kind of API and how it simplifies the entire process and makes it "more reliable, easier to use, easier to port, and easier to debug."

tagged: restful rest api jsonpure problem lie opinion

Link: http://mmikowski.github.io/the_lie/

SitePoint PHP Blog:
Using Sphinx for PHP Project Documentation
Aug 17, 2015 @ 09:19:04

The SitePoint PHP blog has posted a guide to using Sphinx, a documentation generation tool that's used behind the scenes for the ReadTheDocs hosted documentation service.

I recently had the need to write proper prose-like source-code documentation for the Diffbot PHP client. Having looked at several documentation generators, and even having suggested a @prose tag for importing of related MD/reST documents into method and class descriptions, I realized there simply is no perfect solution we can all agree on (yet). So until I extend Sage with a @prose token and reST parsing, I opted for ReadTheDocs and Sphinx.

He starts with a quick "TL;DR" of the necessary commands to get things working quickly but follows it with the full details. He walks you through the installation of Sphinx locally, setting up the folders and adding a custom theme. He show how to create the table of contents, activate the PHP syntax highlighting and how to show/hide the "Edit on GitHub" links. He also includes the steps to convert Markdown documents into the reST format and, finally, adding the project to the ReadTheDocs site and pushing your results.

tagged: sphinx project documentation tutorial readthedocs markdown rest

Link: http://www.sitepoint.com/using-sphinx-for-php-project-documentation/

SitePoint PHP Blog:
WP API and OAuth – Using WordPress without WordPress
Jul 16, 2015 @ 13:08:54

The SitePoint PHP blog has posted a tutorial showing you how to "use WordPress without WordPress" via a basic RESTish API installed via plugin. The article focuses on using the OAuth authentication method to connect a client to the WP instance, linked to a system user via generated tokens.

In this tutorial, we’ll learn how to install and use WP-API with OAuth – a WordPress plugin which uses REST-like API endpoints to allow reading of WP content to unauthenticated users, and writing of WP content to users who authenticate via OAuth (or via Cookies for themes and plugins). Using the plugin isn’t very straightforward, and the prerequisite list is quite long, so this post was written to make it simple and relatively approachable (as long as you’re in control of your own server).

The tutorial walks you through the steps to get a WordPress instance installed (via a git clone) and setting it up to work with Homestead Improved. He then installs the "wp-cli" tool to get the OAuth1 plugin needed to make things work correctly and how to use it to generate the needed key and secret for the OAuth connection. He then makes a simple script that uses the Guzzle HTTP client and it's OAuth handling to make the OAuth request for a token, call the callback page and return the bearer token for the remainder of the requests. Finally he creates a simple page that uses this token to submit a new article via the API and views it in the WordPress interface.

tagged: wordpress api tutorial oauth guzzle oauth1 wpcli rest

Link: http://www.sitepoint.com/wp-api-and-oauth-using-wordpress-without-wordpress/

Sameer Borate:
Accessing WordPress data using the new REST api
Jul 16, 2015 @ 09:53:57

Sameer Borate has posted an article showing you how to use the WordPress REST API (set up by this plugin) to access the data housed inside your WP installation.

WordPress is without doubt the most used CMS system around. Various sources peg the usage around 20-30% of all web sites. Whatever the correct figure, there is no doubt that the collective content of WordPress sites is enormously large. However almost all content is virtually held in independent WordPress sites with no way to easily access a sites content programmatically. [...] As WordPress is moving towards becoming a fully-fledged application framework, we need new APIs. At present a REST api plugin is available to access your site’s data in simple JSON format, including users, posts, taxonomies and more.

He walks you through the installation of the plugin and how to make a request to the REST API's test endpoint to ensure everything's functioning correctly. He also includes an example request that fetches the contents of a post by it's ID. The tutorial wraps up with a look at authentication and how the plugin provides two kinds of handling: basic authentication (HTTP Auth) and OAuth. You can find out more about the structure and functionality of the API on the project's website.

tagged: wordpress rest api tutorial installation setup plugin

Link: http://www.codediesel.com/wordpress/accessing-wordpress-data-using-the-new-rest-api/

MyBuilder Tech Blog:
Managing Jenkins Project Builds and Configuration using PHP
Jul 08, 2015 @ 09:57:22

The MyBuilder.com Tech blog has posted a tutorial showing you how to manage your Jenkins builds and configuration using PHP via the Jenkins REST API interface and a few handy curl calls.

I decided to create a simple PHP console script that can be run (or added as a git-hook) to maintain synchronization between the branch you are working on and the branch Jenkins is building. Whilst developing this script, it dawned on me that many other automated use-cases could be achieved with the ability to easily update a projects configuration file. [...] Jenkins fortunately provides us with a RESTful interface to manage typical tasks and activities. Included in this is the ability to read the XML configuration file for a specified project.

The tutorial includes examples of requests you can make to the API to do things like:

  • Reading the Projects Configuration
  • Writing to the Projects Configuration
  • Sending a Project Build Request

The post ends with the full script, a procedural process that executes each of the above steps in order (with an interesting use of the "goto" functionality).

tagged: manage jenkins build project configuration rest api tutorial curl

Link: http://tech.mybuilder.com/managing-jenkins-project-builds-and-configuration-using-php/

Creating a Dating Application with Sinch: RESTful API
Apr 27, 2015 @ 10:19:26

NetTuts.com has kicked off a new tutorial series today about building a dating application with a combination of Laravel, MongoDB and the Sinch service allowing for messaging between users. The Sinch service has several features including voice/messaging/SMS communication methods and device verification.

In this tutorial, we're going to create a dating application for iOS similar to Tinder. For voice and messaging, we will leverage the Sinch platform, making use of its powerful SDK. In the first part, we will focus on the development of a RESTful API to store and retrieve user information. In the second part, the iOS client will hook into this API to find nearby users based on the user's current location. We will use Laravel 5.0 for the RESTful service and will be covering basic concepts, such as routes and controllers. We are also going to define custom models to support MongoDB integration in an ActiveRecord-like manner.

This first part of the series is mostly about just getting things set up so they walk you through:

  • Basic setup of the Laravel application
  • Creation of the Base model (for MongoDB connection)
  • Creating helper methods
  • Building out CRUD functionality for the database layer
  • Making a User model
  • Creating the BaseController class
  • Making a SessionController class (and working with sessions)
  • Building a UserController

They end this part of the series by hooking all of this functionality together with some simple RESTful routing for GET, POST, PUT and DELETE request handling for the various endpoints.

tagged: tutorial series laravel sinch messaging rest api framework part1

Link: http://code.tutsplus.com/tutorials/creating-a-dating-application-with-sinch-restful-api--cms-23709

Working with the PayPal API
Mar 27, 2015 @ 09:57:34

PHPBuilder.com has posted a tutorial showing you how to interact with the PayPal API via your PHP application using their own PHP-SDK.

PayPal recently introduced a new RESTful API that is more convenient and more powerful than the previous version. In this article, I will show you how to integrate your PHP application with the new PayPal API.

They start with a summary of the PayPal API and how to get the SDK loaded and ready to use (either through Composer or manually). The tutorial walks you through the authorization process (OAuth) and the code you'll need to make it happen. They also show you how to create transaction (including currency type and description) after the items have been submitted. There's also some code showing you how to get the current status of the payment once it has been submitted.

tagged: paypal api tutorial introduction phpsdk rest

Link: http://www.phpbuilder.com/articles/application-architecture/shopping-carts/working-with-the-paypal-api.html

Sameer Borate:
Create a quick REST API using Slim framework
Mar 16, 2015 @ 10:16:40

Sameer Borate has a quick tutorial posted showing how to create a basic REST API with Slim, the popular microframework for PHP.

During a recent client project, I frequently needed to access a remote database table and update the same for certain fields. This was accomplished using phpMyAdmin on the server. However, it was getting tedious and was prone to accidental updates and deletes. [...] This is all a tedious process and prone to errors. One solution was to create a quick REST api wrapper around the remote database, using which developers could update the database table without any risk of corrupting the data and also with the added benefit of updating the table programmatically.

He uses an example of working with student data (SQL for the table included) and helps you get Slim installed and working with an Apache install. He covers the overall structure of the API he's creating and the code to help make it happen. Obviously he doesn't share the entire codebase - that would be too large. He does show examples of GET and POST requests for the student data to give you something to work from. He finishes the post with a few simple cURL calls to make requests to the API and the responses.

tagged: rest api tutorial slim microframework example student

Link: http://www.codediesel.com/php/create-a-quick-rest-api-using-slim-framework/

SitePoint PHP Blog:
RAML, the RESTful API Modeling Language
Feb 02, 2015 @ 10:52:58

The SitePoint PHP blog has a new post today introducing RAML, a modeling language made specifically for use in APIs to define services available.

n a recent article I introduced Slate, a static site generator specifically designed for writing API documentation. This time around, I’m going to look at something which in many ways is even better. But first, if you’ll indulge me for just a moment, I’d like to begin by quoting myself from that article; "[an] API is only as good as its documentation." I think it’s worth repeating, since it’s all-too-frequently overlooked, and it’s one of the motivations for this short series of articles on some of the tools out there to help you write great documentation.

RAML (RESTful API Modeling Language) provides a structured, unambiguous format for describing a RESTful API. It allows you to describe your API; the endpoints, the HTTP methods to be used for each one, any parameters and their format, what you can expect by way of a response and more.

He starts off with a few things that RAML is particularly good at helping with, including being used to generate other documentation. He then moves into writing up some of the actual RAML documentation, noting that it's a derivative of YAML and is just made from text files. He walks through the creation of a sample RAML document including the overall summary information, describing resources, HTTP methods and response structure. He also includes examples of defining query parameters, request data and any security requirements you might have. Finally, he suggests the raml2html tool if you want to generate some HTML output of your configuration, making it easier for normal humans to read.

tagged: raml api rest modeling language documentation requirements endpoints

Link: http://www.sitepoint.com/raml-restful-api-modeling-language/

Michelangelo van Dam:
Running Apigility on Azure
Nov 21, 2014 @ 11:55:15

Michelango van Dam has a new post on his site today walking you through the process of running Apigility on Windows Azure. Apigility is a project from Zend that makes creating and maintaining APIs much simpler (based on the Zend Framework).

Since a couple of years I've been a fan of Microsoft Azure, the cloud platform by Microsoft. It offers a platform as a service (PaaS) in the form of Azure Websites which makes it a great solution to prototype and to play with new stuff. Last year Matthew Weier O'Phinney announced Apigility at ZendCon, a manager for API design. It was immediately clear that it would revolutionise the way we would design and manage REST API's.

Michelangelo walks you through the entire process, starting locally. He shows you how to clone and set up the latest version of Apigility and create a basic endpoint named "demo". He adds in a bit of code to handle the API request (returning user data) and includes an example of what the REST request looks like. With that up and running, he moves on to the Azure side of things. He shows you how to create a "web.config" file to configure the Azure server and run Composer as the install is being processed. He helps you get an Azure account set up and shows how to set up the website instance where you'll deploy the application, pointing it to a GitHub repository as a deploy source.

tagged: apigility windows azure deploy tutorial introduction rest api

Link: http://www.dragonbe.com/2014/11/running-apigility-on-azure.html