diff --git a/docs/index.html b/docs/index.html index 2653c42..af79d65 100644 --- a/docs/index.html +++ b/docs/index.html @@ -213,6 +213,7 @@
Navigation



+

diff --git a/docs/pages/developing-extensions/Custom-web-routes.md b/docs/pages/developing-extensions/Custom-web-routes.md new file mode 100644 index 0000000..b8fb9d7 --- /dev/null +++ b/docs/pages/developing-extensions/Custom-web-routes.md @@ -0,0 +1,125 @@ +
+
+ +
+

+ Written by those who've walked the path. Want to improve our guides? Contribute and help build something awesome! +

+ + + +

+ +# Creating custom web routes +

Add your own web routes accessible from everywhere within Blueprint.


+ +This guide provides a step-by-step overview on how to define custom web routes using a dedicated controller within a Blueprint extension.

+ +### **Define the controller directory and routing file** + +Begin by creating a new directory within your extension to store your controller classes. In this example, we will use a directory named `controllers`. + +Next, open your `conf.yml` file and define the location of your controller directory and route file under the `requests` section. This allows Blueprint to recognize and load your custom logic. + +```yml +requests: + views: "" + app: "controllers" + routers: + application: "" + client: "" + web: "routes.php" +``` + +- `app`: Points to the folder containing your controller classes. +- `routers:web`: Defines the file responsible for registering your web routes. + + + +Depending on your use case, you may also define routes using `routers:application` or `routers:client`. Unlike `web` routes, which are publicly accessible, even to unauthenticated users, these route types are protected: + +- `client`: Can only be accessed by logged in user and via API key. +- `application`: Can only be accessed via API key. Exact permissions can be defined. + +Each route also has a different url prefix: + +- `application`: `/api/application/extensions/{identifier}` +- `client`: `/api/client/extensions/{identifier}` +- `web`: `/extensions/{identifier}` + + +### **Creating a controller** + +Inside the `controllers` directory, create a PHP file named after your controller class. The file and class name **must match exactly**. + +In this example, we will create a controller that handles routes for the dashboard and name the file `ExtensionDashboardController.php`. + +```php +json([ + 'status' => 'success', + ]); + } +} +``` +- This controller defines a `getData()` method that returns a JSON response. + +
+ +### **Registering routes** + +Create a PHP file named `routes.php` (or another name, as long as it matches your `conf.yml`) to define your routes. + +```php + + +
Be sure to update the second use statement to match the correct namespace and class name of your controller.
+
+ +
+ +
+ Previous + Next +
diff --git a/docs/pages/developing-extensions/Packaging-extensions.md b/docs/pages/developing-extensions/Packaging-extensions.md index ccbbd54..62bc341 100644 --- a/docs/pages/developing-extensions/Packaging-extensions.md +++ b/docs/pages/developing-extensions/Packaging-extensions.md @@ -38,6 +38,6 @@ To package an extension for distribution, we need to convert it into a `identifi After running one of these commands, you'll be left with a `identifier.blueprint` file which you can in turn use to distribute your extension to the outside world.
- Previous + Previous
\ No newline at end of file diff --git a/docs/pages/developing-extensions/React-components.md b/docs/pages/developing-extensions/React-components.md index ef7a8c2..fb2b25f 100644 --- a/docs/pages/developing-extensions/React-components.md +++ b/docs/pages/developing-extensions/React-components.md @@ -91,5 +91,5 @@ With the code mentioned above, you've added the `Content.tsx` component into the
Previous - Next + Next