# Separated endpoints based on header is present or not

**URL:** <https://softwaremill.community/t/separated-endpoints-based-on-header-is-present-or-not/296>\
**Category:** tapir\
**Created:** [October 19, 2023, 8:56am UTC](https://softwaremill.community/t/separated-endpoints-based-on-header-is-present-or-not/296 "2023-10-19T08:56:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterlopen](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/peterlopen/32/194_2.png) [@peterlopen](https://softwaremill.community/u/peterlopen)\
**Post date:** [October 19, 2023, 8:56am UTC](https://softwaremill.community/t/separated-endpoints-based-on-header-is-present-or-not/296/1 "2023-10-19T08:56:06Z")

</div>

hi,  
how to define endpoint that will return 403 for all PUT request not containing specific header with name game-id? I want to also define endpoints that will accept PUT request in case header is present.  
current API does not seems to support chatgpt’s suggestion

```auto
.when(gameIdHeader.notPresent)

```

🙂  
thank you  
regards,  
peter

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [October 19, 2023, 9:14am UTC](https://softwaremill.community/t/separated-endpoints-based-on-header-is-present-or-not/296/2 "2023-10-19T09:14:05Z")

</div>

Hey,

I’m not sure if chat-gpt’s cutoff date allows it to include much information on tapir 🙂

Anyway, to implement such an endpoint, I think the simplest solution would be sth as follows:

```plaintext
val myServerEndpoint = endpoint.put
  .in(header[Option[String]]("game-id"))
  .errorOut(statusCode)
  .out(stringBody)
  .serverLogic(header =>
    header match {
      case None => Future.successfull(Left(StatusCodes.Forbidden))
      case Some(v) => Future.successfull(Right("ok"))
    }
  )

```

Of course you’ll probably want to do more in the endpoint.

Alternatively, if you’d like to mark the header as required in the docs, you can use a required endpoint: `header[String]("game-id")` and modify the response, in case the endpoint fails to decode, using a custom [decode failure handler](https://tapir.softwaremill.com/en/latest/server/errors.html#decode-failures).
