title: How do I write a middleware for vapor web framework?
body: <p>Created a new project using toolbox command: vapor new projectname</p>
  
  <p>In main.swift file I added the middleware code:</p>
  
  <pre><code>import Vapor
  import HTTP
  
  final class VersionMiddleware: Middleware {
      func respond(to request: Request, chainingTo next: Responder) throws -&gt; Response {
          let response = try next.respond(to: request)
  
          response.headers["Version"] = "API v1.0"
          print("not printing")
  
          return response
      }
  }
  
  let drop = Droplet(availableMiddleware: [
      "version": VersionMiddleware()
  ])
  
  drop.get("hello") {
      req in 
      return "Hello world"
  } 
  
  drop.run()
  </code></pre>
  
  <p>But when I run this, it prints "hello world" but the API version is not added to headers. I am checking it using postman.</p>