Trongate Docs
switch to dark modeswitch to dark mode
»
»
Trongate's Built-In Endpoints

Trongate's Built-In Endpoints

The Trongate framework comes with an assortment of built-in API endpoints.  The PHP code for all of these endpoints can be found inside a file named 'Api.php', which is inside the engine folder. Trongate's built-in endpoints are:

  • Get
  • Get By Post
  • Find One
  • Exists
  • Count
  • Count By Post
  • Create
  • Insert Batch
  • Update
  • Destroy
  • Delete One

All of the methods for the above endpoints are defined inside Api.php, which is inside the engine folder.  Whenever you generate a new module, using the Trongate Desktop App, an api.json file is automatically created and added to the 'assets' folder of your new module.  This file contains an assortment of API endpoint definitions for your new module.

Top Tip
Don't be alarmed when you see lots of API endpoints suddenly being defined whenever you create a new module, using the Desktop App.  The Trongate API Explorer will not work unless your app is in 'dev' mode.  Furthermore, inbuilt API endpoints will not work unless authorization rules have been declared.  In the case of the Trongate Desktop App, the default endpoints that are declared have conservative authorization rules.  In other words, you're (probably!) not going to get hacked!

The best way to see a visual representation of Trongate's built-in endpoints is to generate a module, using the desktop app, then visit your base URL followed by api/explorer/module, where 'module' gets replaced by the name of your target module directory.

Just To Let You Know
For the API Explorer to work, there must be a database table that shares the same name as your target module directory.

The Trongate API Explorer

Key Features

Trongate's built-in API endpoints share the following key features:

  • They can be universally applied to any database table
  • They are all respectful of Trongate's token security system
  • They will all remain in a deactivated state unless authorization rules have been declared

Endpoint Settings

How endpoints are activated and how they behave is declared inside the api.json file that should be created and stored inside the 'assets' folder of your target module.  An example of an api.json file that has been generated by the Trongate Desktop App is shown below.  What each of the settings does is (hopefully!) self explanatory:

{
  "Get": {
    "url_segments": "api/get/members",
    "request_type": "GET",
    "description": "Fetch rows from table",
    "enableParams": true,
    "authorization":{
      "roles": [
        "admin"
      ]
    }
  },
  "Get By Post": {
    "url_segments": "api/get/members",
    "request_type": "POST",
    "description": "Fetch rows from table using POST request.",
    "enableParams": true,
    "authorization":{
      "roles": [
        "admin"
      ]
    }
  },
  "Find One": {
    "url_segments": "api/get/members/{id}",
    "request_type": "GET",
    "description": "Fetch one row",
    "required_fields": [
      {
        "name": "id",
        "label": "ID"
      }
    ]
  },
  "Exists": {
    "url_segments": "api/exists/members/{id}",
    "request_type": "GET",
    "description": "Check if instance exists",
    "required_fields": [
      {
        "name": "id",
        "label": "ID"
      }
    ]
  },
  "Count": {
    "url_segments": "api/count/members",
    "request_type": "GET",
    "description": "Count number of records",
    "enableParams": true
  },
  "Count By Post": {
    "url_segments": "api/count/members",
    "request_type": "POST",
    "description": "Count number of records using POST request",
    "enableParams": true,
    "authorization":{
      "roles": [
        "admin"
      ]
    }
  },
  "Create": {
    "url_segments": "api/create/members",
    "request_type": "POST",
    "description": "Insert database record",
    "enableParams": true
  },
  "Insert Batch": {
    "url_segments": "api/batch/members",
    "request_type": "POST",
    "description": "Insert multiple records",
    "enableParams": true
  },
  "Update": {
    "url_segments": "api/update/members/{id}",
    "request_type": "PUT",
    "description": "Update a database record",
    "enableParams": true,
    "required_fields": [
      {
        "name": "id",
        "label": "ID"
      }
    ]
  },
  "Destroy": {
    "url_segments": "api/destroy/members",
    "request_type": "DELETE",
    "description": "Delete row or rows",
    "enableParams": true
  },
  "Delete One": {
    "url_segments": "api/delete/members/{id}",
    "request_type": "DELETE",
    "description": "Delete one row",
    "required_fields": [
      {
        "name": "id",
        "label": "ID"
      }
    ]
  }
}

Don't worry if the code above looks confusing.  We'll be going into all of this, in detail, in the pages that are coming right up!





HELP & SUPPORT

If you have a question or a comment relating to anything you've see here, please goto the Help Bar.

 
×