NAME

WWW::Suffit::Server::API - The Suffit API controller

SYNOPSIS

use WWW::Suffit::Server::API;

DESCRIPTION

The Suffit API controller

METHODS

List of internal methods

api

See "GET /api"

check

See "GET /api/check"

is_connected

This method connects to the authorization database and returns the connection status

my $r = $app->routes->under('/')
    ->to('API#is_connected')
    ->name('__authdb');

API METHODS

List of API methods

GET /api

This method returns general statistics of the API server, available only after authorization

# curl -v -H "Authorization: Bearer eyJh...s5aM" \
  https://localhost:8695/api

> GET /api HTTP/1.1
> Host: localhost:8695
> User-Agent: curl/7.68.0
> Accept: */*
> Authorization: Bearer eyJh...s5aM
>
< HTTP/1.1 200 OK
< Content-Length: 3188
< Content-Type: application/json;charset=UTF-8
< Date: Wed, 14 Aug 2024 08:05:01 GMT
< Server: OWL/1.11
< Vary: Accept-Encoding
<
{
  "algorithms": [ "MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512" ],
  "api_version": "1.02",
  "base_url": "https://localhost:8695",
  "code": "E0000",
  "datetime": "2024-08-14T08:05:01Z",
  "elapsed": 0.000289,
  "entities": {
    "Default": [ "Allow", "Deny" ],
    "Env": [
      "LANG", "LOGNAME", "MOJO_MODE", "USER", "USERNAME",
      "USR1", "USR2", "USR3"
    ],
    "Header": [
      "Accept", "Host", "User-Agent", "X-Token", "X-Auth",
      "X-Usr1", "X-Usr2", "X-Usr3" ],
    "Host": [ "Host", "IP" ],
    "User/Group": [ "User", "Group", "Valid-User" ]
  },
  "files": {
    "datadir": "/tmp/data",
    "documentroot": "/tmp/public",
    "home": "/tmp/www",
    "homedir": "/tmp/www",
    "logfile": null,
    "render_paths": [
      "/tmp/templates", "/tmp/public", "/tmp/www"
    ],
    "static_paths": [ "/tmp/public", "/tmp/www" ],
    "tempdir": "/tmp"
  },
  "generated": 1723622701,
  "is_authorized": true,
  "message": "Ok",
  "methods": [
    "CONNECT", "OPTIONS", "HEAD", "GET", "POST", "PUT",
    "PATCH", "DELETE", "TRACE", "ANY", "MULTI"
  ],
  "namespaces": [
    "WWW::OWL::Server::Controller",
    "WWW::OWL::Server",
    "WWW::Suffit::Server"
  ],
  "operators": [
    { "name": "eq", "operator": "==", "title": "equal to" },
    { "name": "ne", "operator": "!=", "title": "not equal" },
    { "name": "gt", "operator": ">", "title": "greater than" },
    { "name": "lt", "operator": "<", "title": "less than" },
    { "name": "ge", "operator": ">=", "title": "greater than or equal to" },
    { "name": "le", "operator": "<=", "title": "less than or equal to" },
    { "name": "re", "operator": "=~", "title": "regexp match" },
    { "name": "rn", "operator": "!~", "title": "regexp not match" }
  ],
  "project": "XXX",
  "providers": [ "Default", "User/Group", "Host", "Env", "Header" ],
  "public_key": "-----BEGIN RSA PUBLIC KEY-----...",
  "remote_addr": "127.0.0.1",
  "requestid": "MsojYEwbL8Nx",
  "route": "api-data",
  "status": true,
  "token": "eyJh...BQIM",
  "trustedproxies": [ "127.0.0.1", "10.0.0.0/8" ],
  "user": {
    "attributes": "",
    "cachekey": null,
    "comment": "Test user for internal testing only",
    "email": "test@owl.localhost",
    "email_md5": "163e50783979333ebae6fd63b2d96d16",
    "expiration": 1723708629,
    "expires": 1723622701,
    "flags": 31,
    "groups": [ "user" ],
    "name": "Test User",
    "public_key": "-----BEGIN RSA PUBLIC KEY-----...",
    "role": "Test user",
    "username": "test"
  },
  "version": "1.11",
  "year": "2024"
}

GET /api/check

This method simply checks the readiness state of the Suffit API server to interaction

NOTE! The method does not require authorization

# curl -v https://localhost:8695/api/check

> GET /api/check HTTP/1.1
> Host: localhost:8695
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 241
< Content-Type: application/json;charset=UTF-8
< Date: Wed, 14 Aug 2024 07:31:08 GMT
< Server: OWL/1.11
<
{
  "api_version": "1.02",
  "base_url": "https://localhost:8695",
  "code": "E0000",
  "datetime": "2024-08-14T07:31:08Z",
  "message": "Ok",
  "project": "OWL",
  "remote_addr": "127.0.0.1",
  "requestid": "l6TPHQ2TX4vl",
  "status": true,
  "time": 1723620668,
  "version": "1.11"
}

GET /api/status

This method returns extended status information about the Suffit API server state

NOTE! The method does not require authorization

# curl -v https://localhost:8695/api/status

> GET /api/status HTTP/1.1
> Host: localhost:8695
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 606
< Content-Type: application/json;charset=UTF-8
< Date: Wed, 14 Aug 2024 07:44:31 GMT
< Server: OWL/1.11
<
{
  "api_version": "1.02",
  "base_url": "https://localhost:8695",
  "code": "E0000",
  "datetime": "2024-08-14T07:44:31Z",
  "elapsed": 0.00079,
  "generated": 1723621471,
  "is_authorized": false,
  "message": "Ok",
  "project": "OWL",
  "public_key": "-----BEGIN RSA PUBLIC KEY-----...",
  "remote_addr": "127.0.0.1",
  "requestid": "6vJjylIPm0mY",
  "route": "api-status",
  "status": true,
  "token": "",
  "version": "1.11",
  "year": "2024"
}

ERROR CODES

The list of public Suffit API error codes

 API   | HTTP  | DESCRIPTION
-------+-------+-------------------------------------------------
 E1030   [---]   Reserved
 ...
 E1059   [---]   Reserved

* -- this code will be defined later on the interface side

See also list of common Suffit API error codes in "ERROR CODES" in WWW::Suffit::API

HISTORY

See Changes file

TO DO

See TODO file

SEE ALSO

Mojolicious, WWW::Suffit, WWW::Suffit::Server, WWW::Suffit::API

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2024 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/