Returning URLs

    As a rule, it's probably better practice to return absolute URIs from your Web APIs, such as , rather than returning relative URIs, such as /foobar.

    • It's more explicit.
    • There's no ambiguity about the meaning of the string when it's found in representations such as JSON that do not have a native URI type.

    REST framework provides two utility functions to make it more simple to return absolute URIs from your Web API.

    There's no requirement for you to use them, but if you do then the self-describing API will be able to automatically hyperlink its output for you, which makes browsing the API much easier.

    Signature:

    You should include the request as a keyword argument to the function, for example:

    reverse_lazy

    Signature:

    Has the same behavior as , except that it returns a fully qualified URL, using the request to determine the host and port.

    1. api_root = reverse_lazy('api-root', request=request)