pionia/pionia-app

The first truly restful PHP framework based on Moonlight architecture.

v1.1.3 2024-07-29 14:02 UTC

This package is auto-updated.

Last update: 2024-09-03 16:14:42 UTC


README

The first PHP REST framework that is truly restful.

It runs on top of ✨ Moonlight ✨ architecture.

Pionia Logo

Creating a project

composer create-project pionia/pionia-app my_simple_project

Please remember to replace my_simple_project with your project name

Directory

app
├── switches
├── services
├── authentications
├── commands
├── middlewares
├── routes.php
vendor
.gitignore
composer.json
composer.lock
index.php
pionia
README.md
settings.ini
  1. 📂 authentication:- This is where authentication backends should reside. These are the strategies that the app will use to authenticate users to the app context.
  2. 📂 middlewares:- This is where all request middlewares reside. These are the classes that run on every request and every response.
  3. 📂 services:- This is where our actual business logic resides.
  4. 📄 switches:- This is where our main app switch resides. This is where we register all our services.
  5. 📄 routes.php:- This is where we register our service switches
  6. 📄 index.php:- This is our entry file to our project.
  7. 📄 pionia:- This is our commandline helper. For every command, we call this file.
  8. 📄 settings.ini:- All settings for our entire project reside here.

After installation, just run the following to start the server

php pionia serve  # http://localhost:8000

By default, the server will run on port 8000, to change that, run the following

php pionia serve -p8080 # http://localhost:8080

Your endpoint is now running on http://localhost:8000/api/v1/

Official Documentation

You can follow along the documentation but its under active development.

Go to documentation here

You can also run php pionia to get a list of all available commands.

Pionia is basically a REST framework. But if you're intending to use it fullstack with any frontend framework of your choice. Run the command :-

php pionia frontend:scaffold

From there, follow the prompts till you get what you need. If your framework uses vite, please share it and we add it to our scaffolding.

Pionia can also serve your SPA from the root of the app. This implies you only host Pionia in the live environment and Pionia will take care of serving your frontend.

If you want to build and serve your frontend with Pionia.

php pionia frontend:build

If you want to revert(remove the build files from your Pionia code), you can reverse this by running

php pionia frontend:build:clean

Assuming you wanted to use like VueJs and by mistake you scaffold React. Running the following command will remove the entire frontend and the configs added to your settings.ini

php pionia frontend:drop

If you're making any http requests from your frontend, we recommend using the jet-fetch library. However, other framework-specific packages are still okay like the z-fetch for z-js.

In the root of your project, run :-

NPM

npm install jet-fetch

YARN

yarn add jet-fetch

Then use the moonlightRequest method of the package to query any moonlight-powered backend.

import { Jet } from 'jet-fetch';
const jet = new Jet({
  baseUrl: 'http://localhost:8000/api/',
});

// unauthenticated requests
const res = await jet.moonlightRequest(
    { 
           service: 'yourService', 
           action: 'yourAction', 
           ...anyOtherData 
    }, 'v2/');

// for jwt-authenticated requests
const res = await jet.secureMoonlightRequest(
        {
               service: 'yourService',
               action: 'yourAction',
               ...anyOtherData
        }, 'v2/');

For details about jet-fetch, follow the readme guide provided here. With the above, Pionia peeps in the frontend too!

Contributions

All forms of contributions are welcome from documentation, coding, community development and many more.

🔥🔥🔥 Goodluck, and happy coding 🔥🔥🔥