rs/)
    * [ Static Files - ` StaticFiles ` ](../../reference/staticfiles/)
    * [ Templating - ` Jinja2Templates ` ](../../reference/templating/)
    * [ Test Client - ` TestClient ` ](../../reference/testclient/)
  * [ FastAPI People  ](../../fastapi-people/)
  * [ Resources  ](../../resources/)

Resources

    * [ Full Stack FastAPI Template  ](../../project-generation/)
    * [ External Links and Articles  ](../../external-links/)
    * [ FastAPI and friends newsletter  ](../../newsletter/)
  * [ About  ](../../about/)

About

    * [ Alternatives, Inspiration and Comparisons  ](../../alternatives/)
    * [ History, Design and Future  ](../../history-design-future/)
    * [ Benchmarks  ](../../benchmarks/)
  * [ Help  ](../../help/)

Help

    * [ Help FastAPI - Get Help  ](../../help-fastapi/)
    * [ Development - Contributing  ](../../contributing/)
  * [ Release Notes  ](../../release-notes/)

Table of contents

  * Use ` ORJSONResponse `
  * HTML Response 
    * Return a ` Response `
    * Document in OpenAPI and override ` Response `
      * Return an ` HTMLResponse ` directly 
  * Available responses 
    * ` Response `
    * ` HTMLResponse `
    * ` PlainTextResponse `
    * ` JSONResponse `
    * ` ORJSONResponse `
    * ` UJSONResponse `
    * ` RedirectResponse `
    * ` StreamingResponse `
      * Using ` StreamingResponse ` with file-like objects 
    * ` FileResponse `
  * Custom response class 
  * Default response class 
  * Additional documentation 

  1. [ FastAPI  ](../..)
  2. [ Learn  ](../../learn/)
  3. [ Advanced User Guide  ](../)

#  Custom Response - HTML, Stream, File, others  ¶

By default, **FastAPI** will return the responses using ` JSONResponse ` .

You can override it by returning a ` Response ` directly as seen in [ Return a
Response directly ](../response-directly/) .

But if you return a ` Response ` directly, the data won't be automatically
converted, and the documentation won't be automatically generated (for
example, including the specific "media type", in the HTTP header ` Content-
Type ` as part of the generated OpenAPI).

But you can also declare the ` Response ` that you want to be used, in the
_path operation decorator_ .

The contents that you return from your _path operation function_ will be put
inside of that ` Response ` .

And if that ` Response ` has a JSON media type ( ` application/json ` ), like
is the case with the ` JSONResponse ` and ` UJSONResponse ` , the data you
return will be automatically converted (and filtered) with any Pydantic `
response_model ` that you declared in the _path operation decorator_ .

Note

If you use a response class with no media type, FastAPI will expect your
response to have no content, so it will not document the response format in
its generated OpenAPI docs.

##  Use ` ORJSONResponse ` ¶

For example, if you are squeezing performance, you can install and use [ `
orjson ` ](https://github.com/ijl/orjson) and set the response to be `
ORJSONResponse ` .

Import the ` Response ` class (sub-class) you want to use and declare it in
the _path operation decorator_ .

For large responses, returning a ` Response ` directly is much faster than
returning a dictionary.

This is because by default, FastAPI will inspect every item inside and make
sure it is serializable with JSON, using the same [ JSON Compatible Encoder
](../../tutorial/encoder/) explained in the tutorial. This is what allows you
to return **arbitrary objects** , for example database models.

But if you are certain that the content that you are returning is
**serializable with JSON** , you can pass it directly to the response class
and avoid the extra overhead that FastAPI would have by passing your return
content through the ` jsonable_encoder ` before passing it to the response
class.

    
    
    from fastapi import FastAPI
    from fastapi.responses import ORJSONResponse
    
    app = FastAPI()
    
    
    @app.get("/items/", response_class=ORJSONResponse)
    async def re