Skip to content

G-PHP is a Backend-as-a-Service(BaaS) designed for those who don't want to pay for 3rd party servers and want to host on their cPanel or any Apache server.

Notifications You must be signed in to change notification settings

syedadeel2/G-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

G-PHP

G-PHP is a Backend-as-a-Service(BaaS) designed for those who don't want to pay for 3rd party servers and want to host on their cPanel or any Apache server. The purpose of developing this to speed up my development for mobile apps / angular apps for storing data to the database. Consider this a simple and lite version of firebase or parse server.

Features!

  • Manage Applications.
  • Domain & IP whitelisting for application api requests.
  • Stats for application api requests usages.
  • table-based data storage using MySQL.
  • OData Syntax for $select, $orderby, $filter, $skip, $top ($filter do not support functions such as contains or startWith. to use the contains use * e.g. $filter=col * mytext)

Tech

G-PHP uses minimum PHP 7.3 & MySql.

Installation

G-PHP designed to use with ease no complicated installation is required. Just copy all the files and folder to your htdocs/public folder and copy the .htaccess file on your site root folder and then create an empty MySQL database and create a user with all the permission for the database.

After that, open the config.php and change the MySQL database details and that's it!

API Usages

G-PHP v1.0.0

Scroll down for code samples, example requests and responses.

Base URLs:

Generate Key for Admin API calls

Enter the url in your browser http|s://your-domain.com/keys/gen This will generate the unique key for your server only to manage the admin-related calls.

Apps

APIs for managing the apps

Get All Applications

Code samples

# You can also use wget
curl -X GET http://your-domain.com/api/admin \
  -H 'Accept: application/json' \
  -H 'x-api-key: string'

GET /admin Get All Applications

Parameters

Name In Type Required Description
Accept header string true none
x-api-key header string true none

Example responses

200 Response

[
  {
  "id": "1",
  "name": "My First BaaS app",
  "description": "this is a test",
  "app_key": "b33428f9-aa0d-456d-a87d-fa37c7e1b1f8",
  "app_api_slug": "baas-app",
  "cors": [
    {
      "id": "1",
      "application_id": "1",
      "domain": "your-whitelisted-domain.com",
      "ip_address": ""
    },
    {
      "id": "2",
      "application_id": "1",
      "domain": "my-domain.com",
      "ip_address": ""
    },
    {
      "id": "3",
      "application_id": "1",
      "domain": "",
      "ip_address": "192.168.0.1"
    }
  ]
 }
]

Responses

Status Meaning Description Schema
200 OK Returns the JSON array with a collection of registered applications in the system None

Update an existing application

Code samples

# You can also use wget
curl -X PUT http://your-domain.com/api/admin?id=1 \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: string'

PUT /admin Update Application

Body parameter - NOTE: you don't need to pass the the whole object except those properties you want to update.

{
  "description": "this is a test",
  "cors": [
    {
      "domain": "domain1.com",
      "updateWith": "domain4.com"
    },
    {
      "ip_address": "127.0.0.1",
      "updateWith": "192.168.0.1"
    }
  ]
}

Parameters

Name In Type Required Description
id query integer(int32) true none
Accept header string true none
x-api-key header string true none
body body UpdateApplicationRequest true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None
{
    "message": "Application updated"
}

Create Application

Code samples

# You can also use wget
curl -X POST http://your-domain.com/api/admin \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'x-api-key: string'

POST /admin Create Application

Body parameter

NOTE: "cors" is an optional property. If you do not want to whitelist, do not include "cors" in the body.

  {
    "name": "My First BaaS app",
    "description": "this is a test",
    "app_api_slug": "baas-app",
    "cors": [
        {
          "domain": "your-whitelisted-domain.com",
        },
        {
          "domain": "my-domain.com",
        },
        {
          "ip_address": "192.168.0.1"
        }
    ]
 }

Parameters

Name In Type Required Description
Accept header string true none
x-api-key header string true none
body body CreateApplicationRequest true none

Example responses

Returns the message and api key for the newly created application. You have to pass g-api-key in the header to manage the store.

{
  "message": "Application was created.",
  "g-api-key": "c41bc073-c613-44d3-8bc3-9aac3392a1dd"
}

Responses

Status Meaning Description Schema
200 OK Returns the message and api key for the newly created application. you have to pass g-api-key in the header to manage the store. None

Delete an existing application

Code samples

# You can also use wget
curl -X DELETE http://your-domain.com/api/admin?id=1 \
  -H 'Accept: application/json' \
  -H 'x-api-key: string'

DELETE /admin Delete Application

Parameters

Name In Type Required Description
id query integer(int32) true none
Accept header string true none
x-api-key header string true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None
{
    "message": "Application Deleted"
}

Stores

This is where you can insert/update/delete/get your store data. Please keep in mind that when creating the app, whatever the app-api-slug you have passed will update the .htaccess accordingly, and you can access your store using the same. E.g. http://your-domain/api/{app-api-slug}/{storename} (http://your-domain/api/adeels-app/dev-store1). Please NOTE that {store_name} can be anything you want to call your store. This will generate the table in MySQL with a prefix of app-api-slug_storeName

This is table-based storage using MySql. This creates a new table for each store along with your app api slug, e.g. baas-app_myStoreName

You do not need to create the schema; upon the first record insert, it will determine the values data type and create the table and columns according to it. Please do not use spaces or any special characters in the json property name except underscores.
For the complex type, it does support array and object in the payload, and the system will generate that column as a JSON column and store the data in JSON format. For a better understanding please take a look at the request samples I've included below.

Store - Insert Record

Code samples

# You can also use wget
curl -X POST http://your-domain.com/api/baas-app/dev-store1 \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'g-api-key: string'

POST /{app-api-slug}/{any-thing} - Insert Record

Body parameter

{
  "string_col": "adeel",
  "int_col": 1233232,
  "long_string_col": "adasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadad",
  "bool_col": true,
  "double_col": 10.23,
  "array_col": [
    1,
    2,
    3
  ],
  "array_col_object": [
    {
      "n1": "v1"
    },
    {
      "n1": "v2"
    },
    {
      "n1": "v3",
      "n2": "bv1"
    }
  ],
  "object_col": {
    "person": "adeel",
    "email": "someemail@email.com"
  },
  "date_time_col": "2020-08-16T15:03:00.000Z"
}

Parameters

Name In Type Required Description
Accept header string true none
g-api-key header string true When you have created the new app, it should have a return response along with g-api-key
body body JSON true none

Example responses

Responses

Status Meaning Description Schema
201 Created none None
{
    "message": "record inserted",
    "record_id": 1,
    "status": true
}

Generic-GetSingleRecordsWithCustomColumns

Code samples

# You can also use wget
curl -X GET http://your-domain.com/api/azeem/members/2?cols=string \
  -H 'Accept: string' \
  -H 'g-api-key: string'

GET /azeem/members/2 Generic - Get Single Records With Custom Columns

Parameters

Name In Type Required Description
cols query string true none
Accept header string true none
g-api-key header string true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None

Response Schema

This operation does not require authentication

Generic-UpdateRecord

Code samples

# You can also use wget
curl -X PUT http://your-domain.com/api/azeem/members/2 \
  -H 'Content-Type: application/json' \
  -H 'Accept: string' \
  -H 'g-api-key: string'

PUT /azeem/members/2 Generic - Update Record

Body parameter

{
  "string_col": "Adeel Rizvi",
  "int_col": 12334567,
  "long_string_col": "this is a long string",
  "bool_col": false,
  "object_col": {
    "person": "Adeel Rizvi",
    "email": "someemail@email.com"
  }
}

Parameters

Name In Type Required Description
Accept header string true none
g-api-key header string true none
body body Generic-UpdateRecordRequest true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None

Response Schema

This operation does not require authentication

Generic-DeleteSingleRecord

Code samples

# You can also use wget
curl -X DELETE http://your-domain.com/api/azeem/members/2 \
  -H 'Accept: string' \
  -H 'g-api-key: string'

DELETE /azeem/members/2 Generic - Delete Single Record

Parameters

Name In Type Required Description
Accept header string true none
g-api-key header string true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None

Response Schema

This operation does not require authentication

Generic-GetAllRecords

Code samples

# You can also use wget
curl -X GET http://your-domain.com/api/azeem/members/all \
  -H 'Accept: string' \
  -H 'g-api-key: string'

GET /azeem/members/all Generic - Get All Records

Parameters

Name In Type Required Description
Accept header string true none
g-api-key header string true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None

Response Schema

This operation does not require authentication

Generic-TruncateStore

Code samples

# You can also use wget
curl -X DELETE http://your-domain.com/api/azeem/members/all \
  -H 'Accept: string' \
  -H 'g-api-key: string'

DELETE /azeem/members/all Generic - Truncate Store

Parameters

Name In Type Required Description
Accept header string true none
g-api-key header string true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None

Response Schema

This operation does not require authentication

Generic-DeleteStore

Code samples

# You can also use wget
curl -X DELETE http://your-domain.com/api/azeem/members/storage \
  -H 'Accept: string' \
  -H 'g-api-key: string'

DELETE /azeem/members/storage Generic - Delete Store

Parameters

Name In Type Required Description
Accept header string true none
g-api-key header string true none

Example responses

Responses

Status Meaning Description Schema
200 OK none None

Response Schema

This operation does not require authentication

Schemas

CreateApplicationRequest

{
  "name": "24h Fitness Gym",
  "description": "Fitness mobile app store",
  "app_api_slug": "azeem",
  "cors": [
    {
      "domain": "domain1.com"
    },
    {
      "domain": "domain2.com"
    },
    {
      "domain": "domain3.com"
    },
    {
      "ip_address": "127.0.0.1"
    }
  ]
}

CreateApplicationRequest

Properties

Name Type Required Restrictions Description
name string true none none
description string true none none
app_api_slug string true none none
cors [Cor] true none none

Cor

{
  "domain": "domain1.com"
}

Cor

Properties

Name Type Required Restrictions Description
domain string false none none
ip_address string false none none

UpdateApplicationRequest

{
  "description": "this is a test",
  "cors": [
    {
      "domain": "domain1.com",
      "updateWith": "domain4.com"
    },
    {
      "domain": "domain2.com"
    },
    {
      "domain": "domain3.com"
    },
    {
      "ip_address": "127.0.0.1",
      "updateWith": "192.168.0.1"
    }
  ]
}

UpdateApplicationRequest

Properties

Name Type Required Restrictions Description
description string true none none
cors [Cor1] true none none

Cor1

{
  "domain": "domain1.com",
  "updateWith": "domain4.com"
}

Cor1

Properties

Name Type Required Restrictions Description
domain string false none none
updateWith string false none none
ip_address string false none none

Generic-InsertRecordRequest

{
  "string_col": "adeel",
  "int_col": 1233232,
  "long_string_col": "adasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadadadasdasdadasdadadad",
  "bool_col": true,
  "double_col": 10.23,
  "array_col": [
    1,
    2,
    3
  ],
  "array_col_object": [
    {
      "n1": "v1"
    },
    {
      "n1": "v2"
    },
    {
      "n1": "v3",
      "n2": "bv1"
    }
  ],
  "object_col": {
    "person": "adeel",
    "email": "someemail@email.com"
  },
  "date_time_col": "2020-08-16T15:03:00.000Z"
}

Generic-InsertRecordRequest

Properties

Name Type Required Restrictions Description
string_col string true none none
int_col integer(int32) true none none
long_string_col string true none none
bool_col boolean true none none
double_col number(double) true none none
array_col [string] true none none
array_col_object [ArrayColObject] true none none
object_col ObjectCol true none none
date_time_col string true none none
null_col string true none none

ArrayColObject

{
  "n1": "v1"
}

ArrayColObject

Properties

Name Type Required Restrictions Description
n1 string true none none
n2 string false none none

ObjectCol

{
  "person": "adeel",
  "email": "someemail@email.com"
}

ObjectCol

Properties

Name Type Required Restrictions Description
person string true none none
email string true none none

Generic-UpdateRecordRequest

{
  "string_col": "Adeel Rizvi",
  "int_col": 12334567,
  "long_string_col": "this is a long string",
  "bool_col": false,
  "object_col": {
    "person": "Adeel Rizvi",
    "email": "someemail@email.com"
  }
}

Generic-UpdateRecordRequest

Properties

Name Type Required Restrictions Description
string_col string true none none
int_col integer(int32) true none none
long_string_col string true none none
bool_col boolean true none none
object_col ObjectCol true none none

Development

Want to contribute? G-PHP is open to improvements, so feel free to create a Pull Request to help the community become greater.

License

MIT

About

G-PHP is a Backend-as-a-Service(BaaS) designed for those who don't want to pay for 3rd party servers and want to host on their cPanel or any Apache server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages