Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

assert_post_request()

Description

Assert API request is using POST method.

Parameters

ColumnTypeDefaultDescription
$force: bool
$force bool Force the assertion

Return

array Returns JSend data back {@see ajax_functions.php} if not POST method

Location

include/api_functions.php lines 268 to 285

Definition

 
function assert_post_request(bool $force): array
    {
    
// Legacy use cases we don't want to break backwards compatibility for (e.g JS api() makes only POST requests but
    // other clients might only use GET because it was allowed if not authenticating with native mode)
    
if (!$force)
        {
        return [];
        }
    elseif (
$_SERVER['REQUEST_METHOD'] === 'POST')
        {
        return [];
        }
    else
        {
        
http_response_code(405);
        return 
ajax_response_fail(ajax_build_message($GLOBALS['lang']['error-method-not_allowed']));
        }
    }

This article was last updated 7th November 2024 20:35 Europe/London time based on the source file dated 25th April 2024 17:25 Europe/London time.