API Reference
Params

Params

Arguments that can be passed to the API via query params.

pub struct ApiQueryArgs {
    /// If true, internal database properties are added with a `__` prefix
    /// Adds a generated `id` property
    /// Not encouraged to use outside of development
    pub internal: Option<bool>,
 
    // -------------------------------------------------------------------------
    // Adds the respective property to the return Feature/FeatureCollection
    // It is encouraged to add these properties through the admin panel instead of using these args!
    /// If true, the `id` property is added
    pub id: Option<bool>,
    /// If true, the `name` property is added
    pub name: Option<bool>,
    /// If true, the `mode` property is added
    pub mode: Option<bool>,
    /// If true, the `geofence_id` property is added
    pub geofence_id: Option<bool>,
    /// If true, the `parent` property is added
    pub parent: Option<bool>,
 
    // -------------------------------------------------------------------------
    // Extras
    /// custom return type of the API request
    ///
    /// Options: [ReturnTypeArg]
    pub rt: Option<String>,
    /// If true, the `group` property is set from the parent property
    pub group: Option<bool>,
 
    // -------------------------------------------------------------------------
    // Name Property Manipulation
    /// If true, the entire `name` property is set to lowercase
    pub lowercase: Option<bool>,
    /// If true, the entire `name` property is set to uppercase
    pub uppercase: Option<bool>,
    /// If provided, the `name` property is split at the provided string/character, each word is capitalized, then rejoined with the same character
    pub capitalize: Option<String>,
    /// If true, the first character of the `name` property is capitalized
    pub capfirst: Option<bool>,
    /// If true, the `parent` property is added as a prefix to the `name`, separated by the provided string/character
    pub parentstart: Option<String>,
    /// If true, the `parent` property is added as a suffix to the `name`, separated by the provided string/character
    pub parentend: Option<String>,
    /// If the `name` property has the `parent` name as part of its value, the `parent` name is replaced with the given string/character
    pub parentreplace: Option<String>,
    /// Spaces in the `name` property are replaced with the given string/character
    pub space: Option<String>,
    /// Underscores in the `name` property are replaced with the given string/character
    pub underscore: Option<String>,
    /// Dashes/Hyphens in the `name` property are replaced with the given string/character
    pub dash: Option<String>,
    /// Replaces any provided string/character with `""` (empty string)
    pub replace: Option<String>,
    /// Trims x number of characters from the front of the `name` property
    pub trimstart: Option<usize>,
    /// Trims x number of characters from the back of the `name` property
    pub trimend: Option<usize>,
    /// If true, the polish characters are converted to ascii
    pub unpolish: Option<bool>,
}

Name Property Manipulation

Since the name property of a geofence may need to be different on a per project basis, in order to cut down on having to maintain multiple copies of the same geofence in the Kōji database, you can manipulate the name property of a geofence at the API level before it is returned to you.

The manipulations mentioned above are executed in the following order:

  1. trimstart
  2. trimend
  3. replace
  4. parentreplace
  5. parentstart
  6. parentend
  7. lowercase
  8. uppercase
  9. capfirst
  10. capitalize
  11. underscore
  12. dash
  13. space
  14. unpolish
  15. A trim function is automatically called at the end to remove start and end whitespace

By taking advantage of the execution order you should be able to manipulate the name property in almost any desirable way.

String args can be provided with or without " surrounding them. If you are using a string with has a space or special characters, it is recommended to use " to surround the string for consistency.

Examples

Given the below fences:

nameparentprojects
NYnull[]
North, NYNY[ReactMap, Poracle]
South, NYNY[ReactMap, Poracle]
East, NYNY[ReactMap, Poracle]
West, NYNY[ReactMap, Poracle]
DCnull[]
North, DCDC[ReactMap, Poracle]
South, DCDC[ReactMap, Poracle]
East, DCDC[ReactMap, Poracle]
West, DCDC[ReactMap, Poracle]

ReactMap API call: (Project that supports unique names per parent)

https://my-koji-url.com/api/v1/feature-collection/ReactMap?parentreplace=""&replace=","

Result:

Features with their parent property set to "NY" (if a parent property is specified in the admin panel) and a clean name, e.g. North, NY => North

nameparent
NorthNY
SouthNY
EastNY
WestNY
NorthDC
SouthDC
EastDC
WestDC

Poracle API call: (Project that should have all unique names)

https://my-koji-url.com/api/v1/poracle/Poracle?group=true&lowercase=true&replace=","&space="_" Poracle styled results with the group property set from the native parent property, names set to lowercase but are otherwise the same

namegroup
north_nyNY
south_nyNY
east_nyNY
west_nyNY
north_dcDC
south_dcDC
east_dcDC
west_dcDC

Playground

A playground is included as part of the Kōji client. You can check it out yourself at http://{your_koji_url}/play