mirror of
https://github.com/friendica/friendica
synced 2025-04-23 07:10:14 +00:00
Changes in api
- Api functions can define an HTTP method to use to call them. "405 Method Not Allowed" is returned on error - Api function that modify data accepts only POST as method. - A list of HTTP return code related exception is added - Api functions throw HTTP exceptions instead of return false or die() - api_call() catches HTTP exceptions and return error message with corret HTTP response code - api_format_items() returns also item activities count (# of like/dislike etc) - api/friendica/photos/list return more info about photos. xml format added. - api/friendica/photo/detail return more info, links to all sizes, no data except if 'size' parameter is passed. xml format added. - new api api/friendica/activity/<verb> and api/friendica/activity/un<verb> to add or remove like/dislike/attend status
This commit is contained in:
parent
835ad28d83
commit
6b60560ea2
5 changed files with 771 additions and 446 deletions
105
include/HTTPExceptions.php
Normal file
105
include/HTTPExceptions.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* Throwable exceptions to return HTTP status code
|
||||
*
|
||||
* This list of Exception has be extracted from
|
||||
* here http://racksburg.com/choosing-an-http-status-code/
|
||||
*/
|
||||
|
||||
class HTTPException extends Exception {
|
||||
var $httpcode = 200;
|
||||
var $httpdesc = "";
|
||||
public function __construct($message="", $code = 0, Exception $previous = null) {
|
||||
if ($this->httpdesc=="") {
|
||||
$this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', str_replace("Exception","",get_class($this)));
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
// 4xx
|
||||
class TooManyRequestsException extends HTTPException {
|
||||
var $httpcode = 429;
|
||||
}
|
||||
|
||||
class UnauthorizedException extends HTTPException {
|
||||
var $httpcode = 401;
|
||||
}
|
||||
|
||||
class ForbiddenException extends HTTPException {
|
||||
var $httpcode = 403;
|
||||
}
|
||||
|
||||
class NotFoundException extends HTTPException {
|
||||
var $httpcode = 404;
|
||||
}
|
||||
|
||||
class GoneException extends HTTPException {
|
||||
var $httpcode = 410;
|
||||
}
|
||||
|
||||
class MethodNotAllowedException extends HTTPException {
|
||||
var $httpcode = 405;
|
||||
}
|
||||
|
||||
class NonAcceptableException extends HTTPException {
|
||||
var $httpcode = 406;
|
||||
}
|
||||
|
||||
class LenghtRequiredException extends HTTPException {
|
||||
var $httpcode = 411;
|
||||
}
|
||||
|
||||
class PreconditionFailedException extends HTTPException {
|
||||
var $httpcode = 412;
|
||||
}
|
||||
|
||||
class UnsupportedMediaTypeException extends HTTPException {
|
||||
var $httpcode = 415;
|
||||
}
|
||||
|
||||
class ExpetationFailesException extends HTTPException {
|
||||
var $httpcode = 417;
|
||||
}
|
||||
|
||||
class ConflictException extends HTTPException {
|
||||
var $httpcode = 409;
|
||||
}
|
||||
|
||||
class UnprocessableEntityException extends HTTPException {
|
||||
var $httpcode = 422;
|
||||
}
|
||||
|
||||
class ImATeapotException extends HTTPException {
|
||||
var $httpcode = 418;
|
||||
var $httpdesc = "I'm A Teapot";
|
||||
}
|
||||
|
||||
class BadRequestException extends HTTPException {
|
||||
var $httpcode = 400;
|
||||
}
|
||||
|
||||
// 5xx
|
||||
|
||||
class ServiceUnavaiableException extends HTTPException {
|
||||
var $httpcode = 503;
|
||||
}
|
||||
|
||||
class BadGatewayException extends HTTPException {
|
||||
var $httpcode = 502;
|
||||
}
|
||||
|
||||
class GatewayTimeoutException extends HTTPException {
|
||||
var $httpcode = 504;
|
||||
}
|
||||
|
||||
class NotImplementedException extends HTTPException {
|
||||
var $httpcode = 501;
|
||||
}
|
||||
|
||||
class InternalServerErrorException extends HTTPException {
|
||||
var $httpcode = 500;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue