Iris
Getting Started
  • What is Iris
  • 📌Getting started
    • Installation
    • Quick start
  • 🔌Routing
    • Middleware
    • API Versioning
  • 🗜️Compression
    • Index
  • ✈️Redirect
    • Redirect from Context
    • Rewrite Middleware
    • Multi Application Instances
  • 🖼️ View/Templates
    • Documentation
    • Benchmarks
    • ➲ Examples
  • 📁File Server
    • Introduction
    • Listing
    • In-memory Cache
    • HTTP/2 Push + Embedded + Cache and Compression
    • The PrefixDir function
    • Serve files from Context
    • ➲ Examples
  • 🌎Localization
    • Documentation
    • Sitemap
    • ➲ Examples
  • 🛡️Security
    • Basic Authentication
    • CORS
    • Sessions & Cookies
    • CSRF
    • JSON Web Tokens
    • Access Control
    • Anti-bot CAPTCHA
    • ➲ Examples
  • 🚀Responses
    • Text
    • HTML
    • Markdown
    • XML
    • YAML
    • Binary
    • JSON
    • JSONP
    • Problem
    • Protocol Buffers
    • MessagePack
    • Gzip
    • Content Negotiation
    • Stream
    • Server-Sent Events
    • HTTP/2 Push
    • Recorder
    • Outroduction
    • ➲ Examples
  • 📥Requests
    • URL Query
    • Headers
    • URL Path Parameters
    • Form
    • Text
    • XML
    • YAML
    • Binary
    • JSON
    • Validation
    • Protocol Buffers
    • MessagePack
    • Gzip
    • ➲ Examples
  • 💉Dependency Injection
    • Documentation
    • Register Dependency from Context
    • Inputs
    • Outputs
    • ➲ Examples
  • 🦏MVC
    • Quick start
    • Documentation
    • Handle Errors
    • Sessions
    • Websockets
    • gRPC
    • ➲ Examples
  • 🤓Resources
    • Examples
    • Starter Kits
    • Publications
    • Benchmarks
    • Support
  • 📘Contents
    • Host
      • Automatic Public Domain with TLS
    • Configuration
    • Routing
      • Path Parameter Types
      • Reverse Lookups
      • Handle HTTP errors
      • Subdomains
      • Wrap the Router
      • Context Methods
    • HTTP Method Override
    • HTTP Referrer
    • URL Query Parameters
    • Forms
    • Model Validation
    • Cache
    • Cookies
    • Sessions
      • Database
      • Flash Messages
    • Websockets
    • Sitemap
    • Localization
    • Testing
Powered by GitBook
On this page

Was this helpful?

  1. 🚀Responses

Outroduction

Iris does offer quite lot amount of helpers to help you out correctly send rich responses to the client. However, you are not limited to those helpers. You can send any data format to the client through ctx.ContentType("a-mime-type") and ctx.Write([]byte).

Available Content Type helpers:

// ContentType sets the response writer's
// header "Content-Type" to the 'cType'.
ContentType(cType string)
// GetContentType returns the response writer's
// header value of "Content-Type".
GetContentType() string
// GetContentType returns the request's
// trim-ed(without the charset and priority values)
// header value of "Content-Type".
GetContentTypeRequested() string

// GetContentLength returns the request's
// header value of "Content-Length".
GetContentLength() int64

Available raw []byte Write helpers:

Write(body []byte) (int, error)
// Writef formats according to a format specifier and writes to the response.
Writef(format string, args ...interface{}) (int, error)
// WriteString writes a simple string to the response.
WriteString(body string) (int, error)
// WriteNotModified sends a 304 "Not Modified" status code to the client,
// it makes sure that the content type, the content length headers
// and any "ETag" are removed before the response sent.
WriteNotModified()
// WriteWithExpiration works like `Write` but it will
// check if a resource is modified,
// based on the "modtime" input argument,
// otherwise sends a 304 status code in order to
// leave the client-side render the cached content.
WriteWithExpiration(body []byte, modtime time.Time) (int, error)
PreviousRecorderNextURL Query

Last updated 2 years ago

Was this helpful?