Child pages
  • Программный вызов API

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageperl
titleпрямые вызовы API
use Abills::Api::Handle;

# Создаём объект работы с API
my $Api = Abills::Api::Handle->new($db, $admin, \%conf, {
  html    => $html,
  lang    => \%lang,
  cookies => \%COOKIES,
  # Если вы хотите получить JSON (например, для передачи в веб)
  # return_type => 'json'
  direct  => 1
});

# GET
my $uid = 147;
my ($response, $status, $content_type) = $Api->call_api({
  METHOD       => "GET",
  PATH         => "/users/$uid",
});

# GET with query params
my $uid = 147;
my ($response, $status, $content_type) = $Api->call_api({
  METHOD       => "GET",
  PATH         => "/users/$uid",
  PARAMS       => \%FORM
});

# POST with body
my ($response, $status, $content_type) = $Api->call_api({
  METHOD  => "POST",
  PATH    => "/portal/newsletter",
  PARAMS  => \%FORM
});

...