pgsql-http (Github)

HTTP client for PostgreSQL, retrieve a web page from inside the database.

SELECT content FROM http_get(‘http://httpbin.org/ip’);
content
—————————–
{“origin”:”24.69.186.43″} +
(1 row)

Functions
http_header(field VARCHAR, value VARCHAR) returns http_header
http(request http_request) returns http_response
http_get(uri VARCHAR) returns http_response
http_post(uri VARCHAR, content VARCHAR, content_type VARCHAR) returns http_response
http_put(uri VARCHAR, content VARCHAR, content_type VARCHAR) returns http_response
http_patch(uri VARCHAR, content VARCHAR, content_type VARCHAR) returns http_response
http_delete(uri VARCHAR) returns http_response
http_head(uri VARCHAR) returns http_response
http_set_curlopt(curlopt VARCHAR, value varchar) returns boolean
http_reset_curlopt() returns boolean
urlencode(string VARCHAR) returns text

ACF: Creating a new field type

The Advanced Custom Fields plugin is packed with loads of useful field types such as text, image and WYSIWYG. However, when working on a project, it may be necessary to create a new type of field to save & load unique data.

This guide will demonstrate how to create a new field type for the ACF plugin.

Download

To make life easier, we put together a comprehensive starter-kit for creating an ACF field type. This starter-kit contains all the necessary files to create a WP plugin and is heavily commented so you can build your field type quickly and confidently!

Field Type Template on Github

Please download a copy of the ACF field type template starter-kit from this Github repository (Click the Green Download Zip button).

https://github.com/AdvancedCustomFields/acf-field-type-template

Once downloaded, take a look around. Here is a list of the files and folders included.

3 Approaches To Adding Configurable Fields To Your WordPress Plugin

Anyone who has created a WordPress plugin understands the need to create configurable fields to modify how the plugin works. There are countless uses for configurable options in a plugin, and nearly as many ways to implement said options. You see, WordPress allows plugin authors to create their own markup within their settings pages. As a side effect, settings pages can vary greatly between plugins. In this article we are going to go over three common ways you can make your plugin configurable. We will start by creating a settings page and create our fields using the default WordPress Settings API. I will then walk you through how to set up your fields with a custom handler. Finally, I will show you how to integrate a great configurable fields plugin Advanced Custom Fields (ACF) into your own plugin.

Create a Settings Options Page for a Plugin

90% of the plugins you use, will have some options in the dashboard. It makes sense to allow users some setting options, to tailor the functionality of a plugin, according to their preference. This can increase the usability of a plugin.

Create an Options Page for a Plugin under Settings Menu

To create a sub-menu for your plugin in the dashboard ‘Settings’ menu, you should use the Settings API provided by WordPress. Using this API, you can register a new options page, with fields for settings. Additionally, you can add settings to an existing options page.

Register Settings For a Plugin

For settings belonging to a particular plugin, you need to register the settings in a single group, with a unique id. For example, you need to write something like the following:

function myplugin_register_settings() {
   add_option( 'myplugin_option_name', 'This is my option value.');
   register_setting( 'myplugin_options_group', 'myplugin_option_name', 'myplugin_callback' );
}
add_action( 'admin_init', 'myplugin_register_settings' );

Here, all the settings fields for the plugin will be grouped under myplugin_options_group. In an options page, this id will be used to display the fields.

Python REST APIs With Flask, Connexion, and SQLAlchemy

The goal of this article is to show you how to use Python 3, Flask, and Connexion to build useful REST APIs that can include input and output validation, and provide Swagger documentation as a bonus. Also included is a simple but useful single page web application that demonstrates using the API with JavaScript and updating the DOM with it.

The REST API you’ll be building will serve a simple people data structure where the people are keyed to the last name, and any updates are marked with a new timestamp.

This data could be represented in a database, saved in a file, or be accessible through some network protocol, but for us an in-memory data structure works fine. One of the purposes of an API is to decouple the data from the application that uses it, hiding the data implementation details.

Good Programers Worry about Data Structures

“. . . unlike every single horror I’ve ever witnessed when looking closer at SCM products, git actually has a simple design, with stable and reasonably well-documented data structures. In fact, I’m a huge proponent of designing your code around the data, rather than the other way around, and I think it’s one of the reasons git has been fairly successful. . . .

“I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships.”

— Linus Torvalds, https://lwn.net/Articles/193245/

The Flask Mega-Tutorial Part XIX: Deployment on Docker Containers

This is the nineteenth installment of the Flask Mega-Tutorial series, in which I’m going to deploy Microblog to the Docker container platform.

For your reference, below is a list of the articles in this series.