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

Sergey Zhuk:
Building a RESTful API Using ReactPHP and MySQL
Feb 25, 2019 @ 18:56:37

In a recent post to his site, Sergey Zhuk walks through the process for building a REST API with ReactPHP and MySQL and a bit of help from a simple routing package to handle the requests.

Today we will be looking at creating a RESTful API using ReactPHP, MySQL and nikic/FastRoute. Let’s look at the API we want to build and what it can do.

He then steps through the development of the REST API:

  • showing the file structure of the resulting application
  • installing dependencies
  • the code to set up the HTTP server for handling requests (using React)
  • building out the database with a user table

He then gets into the main part of the tutorial, showing the build out of each of the routes for the CRUD operations (Create, Read, Update, Delete). He provides both the code to make the endpoint work and examples of the requests they handle.

tagged: rest api tutorial reactphp mysql fastroute

Link: https://sergeyzhuk.me/2019/02/18/restful-api-with-reactphp-and-mysql/

Tomas Votruba:
How we Migrated from Nette to Symfony in 3 Weeks - Part 1
Feb 25, 2019 @ 15:58:27

Tomas Votruba has a post to his site sharing some background on a migration he recently helped perform migrating an application from Nette to Symfony.

On the break of January/February 2019, we migrated whole Entrydo project from Nette to Symfony. It was API backend with no templates, but still, it wasn't as easy as I expected.

Many coffees and beers were drunk during this migration. 0 programmers were too frustrated to give up. Yet, you'd laugh if you knew what took us the most time.

He starts with some of the reasoning why they wanted to make the move and walks through the steps they took to get there:

  • getting ready
  • making a commitment
  • automated migrations > manual changes

He also talks about some "WTF moments" they had along the way where code that should have worked wasn't (and the simple issue that caused them).

tagged: migration nette symfony process background api

Link: https://www.tomasvotruba.cz/blog/2019/02/21/how-we-migrated-from-nette-to-symfony-in-3-weeks-part-1/

Pineco.de:
Subscribing Users to a MailChimp List with Laravel and Guzzle
Oct 08, 2018 @ 20:50:05

On the Pineco.de blog they've posted a tutorial showing how to use Guzzle to subscribe users to a Mailchimp mailing list in a Laravel application. The technique isn't specific to a Laravel application and can be adapted relatively easily for other framework/application types.

Managing users and mailing lists are not a that painful nowadays. Since we have excellent services that can cover all the needs we have, we don’t need to worry about it too much. But still, let’s take a look at how can we handle user subscriptions when Laravel fires different events.

In the tutorial, the request is sent to Mailchimp via the user registration event fired when a new user signs up for the site. They include the code to create the listener and register it in the Laravel configuration. They've also included the code that will be used when the event is fired, sending a message to the Mailchimp API with a "subscribed" status and the user information.

tagged: tutorial subscribe user mailchimp mailinglist laravel guzzle api

Link: https://pineco.de/subscribing-users-to-a-mailchimp-list-with-laravel-and-guzzle/

Pineco.de:
Appending API and Web Routes to Eloquent Models
Aug 22, 2018 @ 17:54:06

The Pineco.de blog has a tutorial posted showing Laravel users how to append API and web routes to Eloquent models directly without the need for setting up additional route handling.

As a level zero, we can agree on using the RESTful URI scheme. That means every model has an associated route. We can perform different actions on the model, depending on the request type.

It can be a bit painful to concatenate the strings and IDs all the time, so we could append this URL as an attribute of the model. That means we could calculate the URL behind the scenes, and use it on the PHP or the JS side as well. [...] Then only difference (in this simple example) between the API and the web routes is that the API routes have a /api prefix in the URL.

The tutorial then introduces their custom Routable trait that can be included in any model to handle requests on both the API and web side (differentiated by the "api" prefix). The last step is to append the routes to the model itself using the appends Eloquent property.

tagged: laravel tutorial append api web route model eloquent

Link: https://pineco.de/appending-api-and-web-routes-to-eloquent-models/

Matthew Weier O'Phinney:
Notes on GraphQL
Jul 19, 2018 @ 15:19:15

In a post to his site Matthew Weier O'Phinney shares some notes about GraphQL usage that he's gathered over the last week or so of working with it.

The last week has been my first foray into GraphQL, using the GitHub GraphQL API endpoints. I now have OpinionsTM.

The promise is fantastic: query for everything you need, but nothing more. Get it all in one go. But the reality is somewhat... different.

He talks about his experience working with the results and the amount of data manipulation that was required to actually get at what he wanted. He shares the query he used, the result the API provided and what he ultimately wanted. He also mentions the less than useful documentation, issues with pagination and an update based on comments of pulling data from the GraphSQL API versus the REST API.

tagged: graphql notes api github request response issues

Link: https://mwop.net/blog/2018-07-18-graphql.html

Laravel News:
Sending a daily email with Laravel and Campaign Monitor
Apr 12, 2018 @ 14:46:08

In a new tutorial on the Laravel News site, the author (Eric Barnes) shows you how to create a Laravel command that will send a daily email newsletter with the help of the Campaign Monitor service.

Here on Laravel News, we offer multiple ways of staying up to date with new content. Everything from auto-sharing to all the social media channels, a read-only Telegram channel, a weekly newsletter and last March we started offering a daily email digest.

To send the daily email we utilize the Laravel scheduler and Campaign Monitor so it’s completely automated. In this tutorial let’s look at how its all setup and how you can easily add this to your site to start sending out automated emails.

The tutorial starts by helping you get the Campaign Monitor SDK package installed (via Composer) and configured to use their API with your own key. Next it walks you through the creation of the console command to hook into the Scheduler for automated sending. It includes the code you'll need to find the data (in this case the latest blog posts) and the email method to send the information to the Campaign Monitor API. There's a brief mention of the creation of the HTML for the newsletter based on the Zurb Foundation and the configuration change to add the command to the scheduler for execution.

tagged: laravel tutorial command newsletter automation campaignmonitor api

Link: https://laravel-news.com/laravel-campaign-monitor

Pineco.de:
Frequently Asked Questions About Laravel based APIs
Mar 15, 2018 @ 15:35:09

On the Pineco.de site there's a new post that answers some of the frequently asked questions they've heard about APIs in Laravel-based applications.

Developing APIs are getting more and more popular, but still, it’s a bit blurry field for many developers. We collected some common questions and tried to answer them in one place.

Their list of questions includes:

  • "What does RESTful mean?"
  • "How does API authentication work?"
  • "Why Laravel has a “web” and an “api ” middleware group?"
  • "How can I test my APIs?"

For each there's a brief summary of the issue and links to other sources (documentation and packages) to help answer or fix the issue.

tagged: laravel api faq question rest authentication middleware testing

Link: https://pineco.de/frequently-asked-questions-about-laravel-based-apis/

Laravel News:
Building a Vue SPA with Laravel Part 2
Jan 30, 2018 @ 18:13:28

The Laravel News site has posted the second part of their tutorial covering the creation of a Laravel-based single page application with Vue.js. This latest tutorial picks up from part one and covers data loading and error handling.

In this tutorial, we continue Building a Vue single-page application (SPA) with Laravel by learning how to load async data from a Laravel API endpoint inside a Vue component. We will also look at error handling when an API response returns an error and how to respond in the interface.

[...] To keep the server-side data simple, our API will use fake data. In Part 3, we will convert the API to a controller with test data coming from a database.

The tutorial starts with the definition of a "users" API route and an update to the API route configuration to map the routes to the correct controllers. Next comes the frontend functionality to load in the user data with the addition of the "users" route to the current Vue.Router instance. The UsersIndex component is then added with the template and functionality to request the data from the backend API. Some final changes are made to the route handling and error handling is added for when the data loading has issues, relaying an error message back to the user.

tagged: laravel tutorial singlepageapp vuejs series part2 api backend users

Link: https://laravel-news.com/building-vue-spa-laravel-part-2

Mustafa Magdi:
Introduction to PHP Reflection API
Dec 28, 2017 @ 17:55:43

Mustafa Magdi has written up a tutorial that introduces you to PHP's Reflection API, functionality included with the language that allows for introspection of the code and some real-time modifications.

When I started PHP coding, I wasn’t aware of the power of Reflection API and the main reason is that I didn’t need it to design my simple class, module or even my package, then I started to find it in many areas playing a major role. So in this part we will introduce Reflection API.

The post is then broken down into a few sections covering the basics of the Reflection functionality, examples of it in use and some other references you can use to get more information. Code examples are included to show how to use the API to do things like:

  • get the parent class for a current class
  • get the docblock comment of a method
  • making private methods available for testing

He also links to two packages that make use of the Reflection API heavily to generate documentation and build a dependency injection container.

tagged: reflection api introduction tutorial beginner

Link: https://medium.com/@MustafaMagdi/introduction-to-php-reflection-api-4af07cc17db4

Symfony Finland:
Adding a GraphQL API to your Symfony Flex application
Dec 01, 2017 @ 17: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


Trending Topics: