Search code examples
httpakka

Akka http unsupported method exception


I have a plain http route defined like so

delete {
           handleErrorsAndReport("delete_foo") {
              fooRepository.deleteFoo(fooId)
              complete(NoContent)
           }
}

I wanted to add some basic authentication to it so now it looks like

seal(
            authenticateBasic(
              realm = "Secure foo",
              scopeAuthenticator
            ) { scopes =>
              delete {
                handleErrorsAndReport("delete_foo") {
                  fooRepository.deleteFoo(fooId, scopes)
                  complete(NoContent)
                }
              }
            }
)

The full directive is

concat(
  get {
  // something else which is working
  },
  seal(
  // something else which is working
  ),
  seal(
              authenticateBasic(
                realm = "Secure foo",
                scopeAuthenticator
              ) { scopes =>
                delete {
                  handleErrorsAndReport("delete_foo") {
                    fooRepository.deleteFoo(fooId, scopes)
                    complete(NoContent)
                  }
                }
              }
  )
)

Now I am getting the following exception when I am trying to delete foos

 Request DELETE http://builder/foos/fooId failed with response code 405 due to request error. Response body: HTTP method not allowed, supported methods: PUT

What could be the issue? The way I've been consuming the API has not changed but I'm afraid that something has changed with the introduction of the seal directive.


Solution

  • I have no idea why but this worked

    concat(
      get {
      // something else which is working
      },
      seal(
                  authenticateBasic(
                    realm = "Secure foo",
                    scopeAuthenticator
                  ) { scopes =>
                    concat(
                       delete {
                         handleErrorsAndReport("delete_foo") {
                           fooRepository.deleteFoo(fooId, scopes)
                           complete(NoContent)
                         },
                         put {//other authenticated endpoint}
                    )
                    }
                  }
      )
    )
    

    In other words, I consolidated the two sealed directives which were before separate. Maybe it's related to this