Skip to content

Quick Start

To better exemplify the benefits of using FastEndpoints we are going to build an API for manipulating blog posts.

This API will be able to:

  • Create
  • Retrieve
  • Update and
  • Delete a blog post

Full source code can be found at matapatos/wp-fastendpoints-my-plugin Β»

Plugin code structure πŸ”¨

To hold this API we are going to create a plugin called MyPLugin - don't forget that logic shouldn't be contained in a theme - with the following structure:

my-plugin
β”‚   my-plugin.php  # Registers the plugin provider
β”‚   composer.json
β”‚
└───src
β”‚   β”‚   constants.php
β”‚   β”‚
β”‚   └───Api
β”‚   β”‚   β”‚
β”‚   β”‚   └───Routers
β”‚   β”‚   β”‚   β”‚   Posts.php  # Holds our custom endpoints
β”‚   β”‚   β”‚
β”‚   β”‚   └───Schemas
β”‚   β”‚       β”‚
β”‚   β”‚       └───Posts
β”‚   β”‚           β”‚   CreateOrUpdate.json  # Validates request payload
β”‚   β”‚           β”‚   Get.json             # Validates responses and discards unwanted fields
β”‚   β”‚
β”‚   β”‚
β”‚   └───Providers
β”‚       β”‚   ApiServiceProvider.php       # Registers all routers
β”‚       β”‚   MyPluginProvider.php         # Bootstraps our plugin
β”‚       β”‚   ProviderContract.php
β”‚
└───tests