details.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .. _rest_api_details:
  2. API details
  3. ===========
  4. This page contains information on the REST API architecture.
  5. Authentication
  6. --------------
  7. REST requires that the client be authenticated. By default, the method of authentication used is Basic authentication. See the :ref:`security` section for how to change the authentication method.
  8. Status codes
  9. ------------
  10. An HTTP request uses a status code to relay the outcome of the request to the client. Different status codes are used for various purposes throughout this document. These codes are described in detail by the `HTTP specification <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_.
  11. The most common status codes are listed below, along with their descriptions:
  12. .. list-table::
  13. :header-rows: 1
  14. * - Status code
  15. - Description
  16. - Notes
  17. * - 200
  18. - OK
  19. - The request was successful
  20. * - 201
  21. - Created
  22. - A new resource was successfully created, such as a new feature type or data store
  23. * - 403
  24. - Forbidden
  25. - Often denotes a permissions mismatch
  26. * - 404
  27. - Not Found
  28. - Endpoint or resource was not at the indicated location
  29. * - 405
  30. - Method Not Allowed
  31. - Often denotes an endpoint accessed with an incorrect operation (for example, a GET request where a PUT/POST is indicated)
  32. * - 500
  33. - Internal Server Error
  34. - Often denotes a syntax error in the request
  35. Formats and representations
  36. ---------------------------
  37. A ``format`` specifies how a particular resource should be represented. A format is used:
  38. * In an operation to specify what representation should be returned to the client
  39. * In a POST or PUT operation to specify the representation being sent to the server
  40. In a **GET** operation the format can be specified in two ways.
  41. There are two ways to specify the format for a GET operation. The first option uses the ``Accept`` header. For example, with the header set to ``"Accept: text/xml"`` the resource would be returned as XML. The second option of setting the format is via a file extension. For example, given a resource ``foo``, to request a representation of ``foo`` as XML, the request URI would end with ``/foo.xml``. To request a representation as JSON, the request URI would end with ``/foo.json``. When no format is specified the server will use its own internal format, usually HTML. When the response format is specified both by the header and by the extension, the format specified by the extension takes precedence.
  42. In a **POST** or **PUT** operation, the format of content being sent to the server is specified with the ``Content-type`` header. For example, to send a representation in XML, use ``"Content-type: text/xml"`` or ``"Content-type: application/xml"``. As with GET requests, the representation of the content returned from the server is specified by the ``Accept`` header or by the format.
  43. The following table defines the ``Content-type`` values for each format:
  44. .. list-table::
  45. :header-rows: 1
  46. * - Format
  47. - Content-type
  48. * - XML
  49. - ``application/xml``
  50. * - JSON
  51. - ``application/json``
  52. * - HTML
  53. - ``application/html``
  54. * - SLD
  55. - ``application/vnd.ogc.sld+xml``
  56. * - ZIP
  57. - ``application/zip``