Best Practice for Errors in RESTful API

后端 未结 3 810
暗喜
暗喜 2021-01-02 08:03

What are the best practices for returning HTTP status codes in RESTful API? I am using Laravel 4 for my PHP framework.

In the case of an error, should I use

3条回答
  •  忘掉有多难
    2021-01-02 08:41

    There are some list of HTTP Status Code at Illuminate\Http\Response that extend to Symfony\Component\HttpFoundation\Response. You can use that in your class.

    For example:

    use Illuminate\Http\Response as LaravelResponse;
    ...
    return Response::json('User Exists', LaravelResponse::HTTP_CONFLICT);
    

    It much more readable.

提交回复
热议问题