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

Symfony Finland:
Adding a GraphQL API to your Symfony Flex application
Dec 01, 2017 @ 11:49:05

On the Symfony Finland site there's a new post sharing a tutorial showing how to add a GraphQL API to your application with the help of the overblog/graphql-bundle bundle.

I've been using GraphQL for some API thingamajigs, and it's been working fine. Now with Symfony 4 out, I figured a write-up on how to use GraphQL with Symfony Flex could be useful for someone.

We'll expand on a previous demo app that I built. That app already uses Doctrine ORM as storage, so let's bridge that to a GraphQL API.

He starts by linking to "a quick read" about GraphQL for those not familiar and listing out the basic structure of the application he'll build out. Next comes the installation of the bundle and a debug bundle to help make it easier to locate errors. He then updates the application configuration to add routes and define the schema for the objects in the system. Using the GUI that comes with the debug package, he shows how to access the API and how to create a "resolver" that will relay the information back to the client from the GraphQL API request.

tagged: symfony graphql api symfonyflex tutorial bundle debug gui

Link: https://symfony.fi/entry/adding-a-graphql-api-to-your-symfony-flex-app

Delicious Brains Blog:
How to Develop a WordPress Plugin Using Webpack 3, React and the REST API (pa
Nov 06, 2017 @ 09:46:31

On the Delicious Brains site they've posted the latest part in their "Develop[ing] a WordPress Plugin Using Webpack 3, React and the REST API" series. This is part two of the series, building on the foundation set up in part one of the series. In this second part more work is put into the Webpack setup, the creation of the REST API and the React frontend.

Have you ever wondered how to get React working with the WordPress REST API? If so you’re in the right place – that’s what we’re going to cover in this follow-up to part one of how to develop a WordPress plugin! In our previous post, we explained what Webpack is and got it integrated into our WordPress sample plugin. We also got BrowserSync set up and reloading our app. In this part we’re going to look at how to get the React side of our plugin working with the WordPress REST API so that the plugin actually does something cool.

The tutorial starts with the Webpack changes, mostly configuration updates adding in additional plugins. Next comes the changes for the REST API and working with it to get information from the WordPress backend. After showing you how to test that the API is working as expected they move along to the React changes on the frontend and using components to split up the logic and make it easier to maintain.

tagged: wordpress rest api tutorial webpack react plugin

Link: https://deliciousbrains.com/develop-wordpress-plugin-webpack-react-rest-api-part-2/

Asmir Mustafic:
How do I deploy my Symfony API - Part 5 - Conclusion
Oct 31, 2017 @ 12:47:25

Asmir Mustafic has finished out his series showing his method for the deployment of Symfony applications with part five sharing some additional improvements that could be made to the system created in the four previous parts.

This is the fifth post from a series of posts that described the whole deploy process from development to production of a Symfony API. This series of blog posts had the aim to show a possible approach to build a continuous integration and continuous delivery pipeline.

The continuous integration and continuous delivery process reduces bugs and makes the development simper. [...] As always happen in software development, solutions are not perfect. There is always room for improvement. Here are few examples of what could have be done better. Obviously can be done better and this are not all the possible improvements that can be done on the system.

In the remainder of the article he includes changes that could be made to the:

  • migration execution, allowing for it to be done between deployments
  • performing health checks of the API
  • Docker container placement
  • putting PHP and Nginx into the same container
  • "node draining" (removing a node from a cluster)

He wraps up the post with a mention of a tool, Kubernetes, that can help to make the configuration and management of your containers easier.

tagged: deploy symfony api tutorial series part5 conclusion

Link: https://www.goetas.com/blog/how-do-i-deploy-my-symfony-api-part-5-conclusion/

Asmir Mustafic:
How do I deploy my Symfony API - Part 4 - Deploy
Oct 11, 2017 @ 10:23:12

Asmir Mustafic has posted the next part of his series covering the deployment of Symfony applications. In this latest article (part four) he focuses on some of the final steps of the deployment process.

This is the forth post from a series of posts that will describe the whole deploy process from development to production. The first article is available here, the second here and the third here.

After covering the steps 1-3 and having prepared our infrastructure, we can see how to deploy our application to production. Almost the same approach can be used to deploy not only to production but also to test environments.

He starts with the workflow for the deployment process, creating a flow where the "git push" should trigger other actions based on the branch pushed. Then CircleCI will fire off a series of jobs to handle environment setup tasks, connecting to a VPN and deploying the code. This includes a bit of preparation, credential handling and the Docker setup and push. Each step along the way also includes all of the YAML configurations you might need to replicate the deployment.

tagged: symfony api deployment part4 series docker configuration example

Link: https://www.goetas.com/blog/how-do-i-deploy-my-symfony-api-part-4-deploy/

Asmir Mustafic:
How do I deploy my Symfony API - Part 3 - Infrastructure
Oct 05, 2017 @ 09:29:06

Asmir Mustafic has posted the third part of his series covering the deployment of Symfony API applications. In this latest part (part three) of the series, he focuses on the infrastructure piece.

This is the third post from a series of posts that will describe the whole deploy process from development to production. The first article is available here and the second here.

In the previous two articles, I've covered the steps 1-3 from the schema here below. Before being able to discuss the steps 4-5 we will need to see how to configure the instances properly to be able to deploy our application to a docker-swarm cluster with rolling updates.

He starts off by describing the pieces that will make up the infrastructure: a PostgreSQL database, Docker swarm for machine/VM management and AWS instances to run the containers on. He then starts in on the instance type and setup you'll need to get the system up and running including manager and worker nodes. The post wraps up with a list of things he sees as improvements for the future such as using a custom AMI, use of elastic load balancers and handling node failure a bit better.

tagged: symfony api deployment tutorial infrastructure part3 series

Link: https://www.goetas.com/blog/how-do-i-deploy-my-symfony-api-part-3-infrastructure/

Armin Weihbold:
Diving into API Platform - Part 2
Oct 02, 2017 @ 11:50:15

Armin Weihbold has continued his series looking at building APIs in PHP applications in part two covering the use of the API Platform project as a base. You can find part one here if you need to get caught up.

He picks up right where the last article ends and continues setting up the Docker environment for the application. Once he figured out a small snag in the setup he was able to get the basic documentation (the list of endpoints) up and running.

Next he creates a "material design" administration interface using React showing how he pulled in the requirements he needed to get the interface up and running. Code is included for the interface and a screenshot is included so you can see the end result.

tagged: api platform apiplatform project tutorial series part2 frontend docker

Link: https://medium.com/@koyaan5/diving-into-api-platform-part-2-1ce890c0b85f

Asmir Mustafic:
How to add custom error codes to your Symfony API responses
Sep 22, 2017 @ 11:10:01

Asmir Mustafic has posted a guide on his site showing how to create custom error codes in the API responses from your Symfony-based application.

When writing APIs, a proper error handling is fundamental. HTTP status codes are a great start, but often when we deal with user inputs is not enough. If out model has complex validation rules, understanding the reason behind an 400 Bad Request error can be not trivial.

Fortunately when for symfony developers there are many libraries to deal with it. Symfony Validator, <a href="https://github.com/symfony/form>Symfony Form, <a href="https://github.com/FriendsOfSymfony/FOSRestBundle>FOS REST Bundle and JMS Serializer combined allows you to have nice error messages to be shown to your users.

He walks you through the code required to create the default error handling with an "author" example. This includes the creation of the entity as well as the form and controller to handle the request/response. He then refactors this away from the default to create the custom error handler with handlers for the message and code to be returned. The post ends with the configuration changes to register it with the application and what the result ends up looking like.

tagged: symfony tutorial custom error code api example

Link: http://www.goetas.com/blog/how-to-add-custom-error-codes-to-your-symfony-api-responses/

SitePoint PHP Blog:
How to Master Your API Workflow with Postman
Aug 21, 2017 @ 11:13:20

On the SitePoint PHP blog author Younes Rafie has returned with another tutorial, this time with a focus on how Postman can help master your API workflow by making use of several of the features it already includes.

Building good APIs is hard, and anyone who had the chance to do so can relate to this. A project can easily grow to become a mess. One can keep trying to adopt an approach to make it more enjoyable, like trying a documentation-first workflow, but something always feels clumsy.

I was trying out Postman lately, a tool we’ve briefly covered before, and I discovered that they’re doing a great job by providing an integrated environment for different components of an API, like authorization, testing, documentation, versioning, etc.

He then goes through the use of the tool, including screenshots along the way for:

  • Making requests
  • Authorization
  • Environment Variables
  • Testing
  • Validating JSON schemas
  • Working with collections

The post finishes up with a look at generating documentation for the API using Postman's "View in Web" feature including integrating example calls and publishing it. There's also a look at exporting and importing data and a few links to some other helpful resources.

tagged: api workflow tutorial postman tool feature screenshot

Link: https://www.sitepoint.com/master-api-workflow-postman/

Zend Framework Blog:
REST Representations for Expressive
Aug 09, 2017 @ 10:12:18

On the Zend Framework blog there's a new post from project lead Matthew Weier O'Phinney covering REST representations in Expressive and the release of two new components to help with their implementation.

We've been working towards our various Apigility on Expressive goals, and have recently published two new components: zend-problem-details and zend-expressive-hal.

These components provide response representations for APIs built with PSR-7 middleware. Specifically, they provide: Problem Details for HTTP APIs (RFC 7807) and Hypertext Application Language (HAL).

These two formats provide both JSON and XML representation options (the latter through a secondary proposal).

The post then goes on to talk about the idea of "representations" and how it relates back to the structure of the data returned and how the user knows what operations they can take on it. He also talks about the differences between normal responses and errors and gives example output helping to illustrate his points. The remainder of the post gets into the details of the two new components, their use and how to implement them in Expressive.

tagged: zendexpressive rest representation data structure response api component tutorial

Link: https://framework.zend.com/blog/2017-08-08-expressive-rest-representations.html

Toptal.com:
Laravel API Tutorial: How to Build and Test a RESTful API
Jul 11, 2017 @ 11:58:15

On the TopTal site they've posted a tutorial from author André Castelo showing you how to create a Laravel-based RESTful API with functionality that already exists in the framework.

With the rise of mobile development and JavaScript frameworks, using a RESTful API is the best option to build a single interface between your data and your client.

Laravel is a PHP framework developed with developer productivity in mind. [...] In this article, we’ll explore the ways you can build—and test—a robust API using Laravel with authentication. We’ll be using Laravel 5.4, and all of the code is available for reference on GitHub.

He starts off by talking about RESTful APIs, what actions the HTTP verbs represent and a note about consistency in URLs. He then starts in on the project setup, creating a new Laravel application and configuring the database for a Homestead environment. Next he creates the models and data seeders for articles and users for the API. Routes and controllers come next showing how to work with route model binding and response codes to correctly relay the status of the request back to the user. Following this he covers authentication on the API (using a token) and building out the endpoints for login, registration and logging out.

Finally he shows how to test the endpoints using some simple Laravel-enabled testing and PHPUnit. His tests check things like login error handling, missing data on registration and the correct flow on the logout process.

tagged: laravel tutorial build test rest api framework

Link: https://www.toptal.com/laravel/restful-laravel-api-tutorial