This is something I used to be able to do in 2.2, but in 2.3 I can't.
A simple controller to handle a POST method, and only receive and send application/json content type.
It works for GET/PUT methods, but if POST, it will render home page (html).
<?php
namespace <vendor>\<module>\Controller\Api;
class MyApi extends \Magento\Framework\App\Action\Action
{
public function execute()
{
$result = $this->createResultJson();
$result->setData([
'message' => 'All Good.'
]);
$result->setHttpResponseCode(200);
return $result;
}
/**
* @return \Magento\Framework\Controller\ResultInterface|\Magento\Framework\Controller\Result\Json
*/
protected function createResultJson()
{
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON);
}
}