Iris Web Framework for Go

repository·main·Indexed 12 days ago

https://github.com/kataras/iris

A fast, simple, and fully-featured web framework for Go, designed for building efficient and expressive websites and APIs. Iris v12 includes support for multiple template parsers, automatic TLS management, and integration with various databases and authentication methods including JWT and BasicAuth.

Tokens
224.1K
Snippets
832
Records
937
Agent score
97%

What's inside Iris

  1. Overview of Iris Web Framework features

    main

    Iris provides a wide array of built-in capabilities for building modern web applications and APIs:

    • Protocols & Communication: HTTP/2 (including Push), WebSockets, gRPC, and automatic HTTPS.
    • Middleware: Includes Accesslog, Basicauth, CORS, gRPC, hCaptcha, JWT, MethodOverride, ModRevision, Monitor, PPROF, Ratelimit, reCaptcha, Recovery, RequestID, and Rewrite.
    • Routing: Unified router supporting dynamic paths with standard types (e.g., :uuid, :string, :int) and custom types.
    • Templating: Support for multiple engines including HTML, Django, Handlebars, and Pug/Jade.
    • Data Handling:
      • Rich Responses: HTML, Text, Markdown, XML, YAML, Binary, JSON, JSONP, Protocol Buffers, MessagePack, Content Negotiation, Streaming, and Server-Sent Events.
      • Rich Requests: Access to URL Query, Headers, Form, Text, XML, YAML, Binary, JSON, Protocol Buffers, and MessagePack with built-in validation.
    • Core Services: Model-View-Controller (MVC), Dependency Injection (MVC, Handlers, API Routers), Sessions, Caching, and Internationalization (i18n/sitemap).
    • Performance: Response compression (gzip, deflate, brotli, snappy, s2) and high-speed execution.
    • Developer Tools: Built-in support for ngrok and a comprehensive testing toolkit.
  2. What is new in Iris v14

    main

    Iris v14 introduces several architectural improvements designed to increase safety, reduce boilerplate, and improve developer experience. Key features include:

    • Compile-checked application chain: The entire application is structured in a way that allows the compiler to verify the integrity of the chain.
    • Reduced Handler Repetition: Handlers are designed to avoid repetitive code patterns.
    • Centralized Error Declaration: Errors are declared once, reducing duplication and improving error handling consistency.
    • Ubiquitous Dependency Injection: Dependency injection is available throughout the framework, extending beyond just the MVC layer.
    • Intuitive Package Structure: Packages are organized in a predictable, logical manner.
    • Partial Literal Configuration: Configuration is handled using partial literals for better flexibility.
    • Semantic Naming: Function and variable names are designed to clearly communicate their purpose.
    • Secure by Default: The framework prioritizes security in its default configurations.
    • Comprehensive Documentation: Documentation is structured to be readable from start to finish.
  3. Overview of Iris v14 features

    main

    Iris v14 is a major rewrite of the framework leveraging Go generics. Key improvements include:

    • Application Builder: Uses iris.NewBuilder() to chain configuration (CORS, Compression, Logging, Health checks, Error maps, Services, and API groups) into a single, compiler-verified chain.
    • Simplified Handlers: Uses rest.ReadJSON[T] to handle decoding and validation in one step, reducing boilerplate.
    • Centralized Error Management: A new rest/errors package maps domain errors to HTTP responses, ensuring consistent machine-readable payloads.
    • Ubiquitous Dependency Injection: DI is available for Handlers, API groups, and Controllers, not just MVC.
    • Refined Package Structure: Middleware like sessions, cache, and websocket are reorganized, and mvc is moved under controller.
    • Partial Literal Configuration: Replaces iris.Configuration with iris.Options, allowing you to specify only the fields you need.
    • Improved Naming: More intuitive API names (e.g., ctx.SetHeader and ctx.ResponseHeader for responses, Party becomes Router).
    • Secure by Default: Includes secure session cookies (Secure and SameSite=Lax) and enforced request body size limits.
  4. Overview of Iris features

    main

    Iris provides a wide range of built-in capabilities for Go web development:

    • Protocols & Communication: HTTP/2 (including Push), Websockets, gRPC, and WebDAV.
    • Middleware: Includes Accesslog, Basicauth, CORS, gRPC, Anti-Bot (hCaptcha/reCaptcha), JWT, MethodOverride, ModRevision, Monitor, PPROF, Ratelimit, Recovery, RequestID, and Rewrite.
    • Routing: Unique router with dynamic path parameters and built-in types like :uuid, :string, :int, with support for custom types.
    • Templating & Views: Support for HTML, Django, Handlebars, Pug/Jade, and more.
    • Data Handling:
      • Rich Responses: HTML, Text, Markdown, XML, YAML, Binary, JSON, JSONP, Protocol Buffers, MessagePack, Content Negotiation, Streaming, and Server-Sent Events.
      • Rich Requests: Binding from URL Query, Headers, Form, Text, XML, YAML, Binary, JSON, Validation, Protocol Buffers, and MessagePack.
    • Response Compression: gzip, deflate, brotli, snappy, and s2.
    • Core Services: API Versioning, Model-View-Controller (MVC), Auto-HTTPS, integrated ngrok support, Cache, Sessions, Localization (i18n, sitemap), and Dependency Injection (MVC, Handlers, API Routers).
    • Testing: Built-in testing tools.
  5. Explore Iris Framework Examples

    main

    The Iris repository contains a vast collection of examples covering various web development scenarios. You can find implementation patterns for:

    • Serverless: Deployment patterns for platforms like Netlify.
    • Databases: Integration with MySQL, MongoDB, Sqlx, Gorm, and Reform.
    • HTTP Server Configuration: Custom listeners, TLS, Let's Encrypt, H2C, and HTTP/3 QUIC.
    • Routing: Middleware (global and per-route), dynamic paths, subdomains, and API versioning.
    • Authentication & Authorization: JWT, OAuth2, Basic Auth, and reCAPTCHA.
    • MVC Pattern: Repository and Service layers, versioned controllers, and session-based controllers.
    • Real-time: WebSockets and Server-Sent Events (SSE).
    • Frontend Integration: Single Page Applications (SPA) with Vue.js and template engines like Jet, Pug, and Handlebars.
  6. Explore Iris Examples by Category

    main

    The Iris repository provides a comprehensive collection of examples to demonstrate various capabilities of the framework. You can find specialized implementations for:

    • HTTP Server & Client: Custom listeners (UNIX, TLS, H2C), graceful shutdown, HTTP/3 Quic, and client-side weather APIs.
    • Routing: Middleware (global and per-route), dynamic paths, subdomains, API versioning, and custom context.
    • Database & ORM: Integration with MySQL, MongoDB, Sqlx, Gorm, and Reform.
    • Authentication & Security: JWT (JSON Web Tokens), OAuth2, Basic Auth, CORS, and reCAPTCHA/hCaptcha.
    • Request/Response Handling: JSON/XML/YAML binding, custom error handling, content negotiation, and Server-Sent Events (SSE).
    • View & Templates: Support for multiple engines including HTML, Jet, Pug, Ace, Django, and Handlebars.
    • MVC: Repository/Service patterns, session controllers, and websocket controllers.
    • Advanced Features: Dependency Injection, WebSockets, Sessions, Compression, and Localization (i18n).
  7. Core features of Iris

    main

    Iris provides a wide array of built-in capabilities for web development:

    • Protocols & Communication: HTTP/2 (Push, embedded data), WebSockets, gRPC, and built-in ngrok support for rapid internet exposure.
    • Routing: A custom router supporting dynamic path parameters with standard types like :uuid, :string, and :int (custom types can also be defined).
    • Middleware: Includes Accesslog, Basicauth, CORS, gRPC, Anti-Bot (hCaptcha/reCaptcha), JWT, MethodOverride, ModRevision, Monitor, PPROF, Ratelimit, Recovery, RequestID, and Rewrite.
    • Data Handling:
      • Requests: Binding and validation for URL Query, Headers, Form, Text, XML, YAML, Binary, JSON, Protocol Buffers, and MessagePack.
      • Responses: Support for HTML, Text, Markdown, XML, YAML, Binary, JSON, JSONP, Protocol Buffers, MessagePack, Content Negotiation, Streaming, and Server-Sent Events.
      • Compression: Response compression via gzip, deflate, brotli, snappy, and s2.
    • Architecture & Patterns: Model-View-Controller (MVC), API Versioning, and Dependency Injection (MVC, Handlers, API Routers).
    • Web Capabilities: View engines (HTML, Django, Handlebars, Pug/Jade), File Servers (including WebDAV hosting), Caching, Sessions, and Localization (i18n, sitemap).
  8. Overview of upcoming Iris v14 features

    main

    Iris v14 is a major rewrite of the framework designed to leverage Go generics. Key improvements include:

    • Compiler-checked application builder: The entire application chain is verified by the compiler.
    • Reduced boilerplate: Handlers and error declarations are streamlined to avoid repetition.
    • Ubiquitous Dependency Injection: DI is available everywhere, extending beyond just the MVC layer.
    • Improved Configuration: Configuration is handled via partial literals.
    • Enhanced Validation: Request helpers provide built-in validation.
    • New Import Path: v14 will use a new import path, ensuring that existing v12 codebases remain unbroken upon release.
  9. What is changing in Iris v14

    main

    Iris v14 introduces several architectural improvements designed to increase safety, reduce boilerplate, and improve developer experience:

    • Compile-checked application chain: The entire application is contained within a single chain that the compiler can verify.
    • Reduced Handler Boilerplate: Handlers no longer require repeating the same code patterns.
    • Unified Error Declaration: Errors are declared once rather than being scattered throughout the logic.
    • Ubiquitous Dependency Injection: Dependency injection is available everywhere, extending beyond just the MVC layer.
    • Intuitive Package Structure: Packages are organized where developers naturally expect them to be.
    • Partial Literal Configuration: Configuration uses partial literals for more flexible setup.
    • Self-documenting Names: API names are designed to clearly express their intent.
    • Secure by Default: The framework is configured with security best practices as the baseline.
    • Comprehensive Documentation: Documentation is designed to be readable from start to finish.
  10. What is coming in Iris v14

    main

    Iris v14 is a major rewrite of the framework leveraging Go generics. It introduces a new application builder pattern, reduces boilerplate in handlers, and centralizes error management.

    Key changes in v14:

    • Compiler-verified application building: Uses iris.NewBuilder() to chain configuration, services, and routes in a single expression that is checked at compile time.
    • Simplified Handlers: Uses rest.ReadJSON[T] to handle decoding and validation automatically, and rest.Created, rest.OK, etc., for standardized responses.
    • Centralized Error Mapping: The rest/errors package allows mapping domain errors to specific HTTP responses in one place.
    • Ubiquitous Dependency Injection: DI is available for handlers, API groups, and controllers via the dep and rest packages.
    • New Package Structure: Many features (sessions, cache, websocket, etc.) have moved to middleware. mvc is now under controller.
    • Configuration via iris.Options: Replaces older configuration methods with a partial literal approach.
    • Improved Naming: More intuitive method names (e.g., ctx.Header for reading requests vs ctx.SetHeader for writing responses).
    • Security by Default: Enhanced session cookie security and request body limits.
  11. What is new in Iris v14

    main

    Iris v14 introduces several architectural improvements designed to increase type safety, reduce boilerplate, and improve developer experience:

    • Compile-checked application chain: The entire application is structured in a single chain that is verified by the compiler.
    • Reduced Handler Repetition: Handlers are designed to avoid repetitive code patterns.
    • Single Error Declaration: Errors are declared once, simplifying error handling logic.
    • Ubiquitous Dependency Injection: Dependency injection is available throughout the framework, extending beyond just the MVC layer.
    • Intuitive Package Structure: Packages are organized in a predictable, logical manner.
    • Partial Literal Configuration: Configuration is handled using partial literals.
    • Semantic Naming: Function and variable names are designed to clearly describe their purpose.
    • Secure by Default: Security measures are integrated into the core defaults.
    • Comprehensive Documentation: The documentation is designed to be read linearly from start to finish.
  12. What is coming in Iris v14

    main

    Iris v14 introduces several architectural improvements designed to enhance developer experience, safety, and maintainability:

    • Compiler-verified application chains: The entire application structure is designed to be verified by the Go compiler.
    • Reduced Handler Redundancy: Handlers are optimized to stop repeating logic.
    • Centralized Error Declaration: Errors are declared once, reducing boilerplate and improving consistency.
    • Ubiquitous Dependency Injection: Dependency injection is available throughout the framework, extending beyond just the MVC layer.
    • Intuitive Package Structure: Packages are organized where developers naturally expect them to be.
    • Partial Literal Configuration: Configuration uses partial literals for more flexible and concise setup.
    • Self-documenting Names: API names are chosen to clearly communicate their purpose.
    • Secure by Default: Security best practices are integrated into the core behavior.
    • Comprehensive Documentation: Designed to be readable and actionable from start to finish.