softwaremill / softwaremill/tapir

How to best implement an output that depends on an input ?

Open
#2,244 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

Use Case:

We have an API that has a JSON output. An input parameter allows to filter the returned JSON fields

The only way to implement this as far as I know is to pass the formatting parameter into the server logic which will then have to encapsulate it in the return type with an appropriate codec.

We have the same problem if we want to recover the input url to build output headers (example Link prev/next headers).

It's quite verbose, and does it really have its place in a "logic" method?

Example:

myEndpoint
  .in(EndpointInputs.searchRequest)
  .in(EndpointInputs.jsonFilterRequest)
  .in(EndpointInputs.extractUri)
  .out(
        headers
          .and(statusCode)
          .and(jsonBody[Seq[FilteredJson[T]]])
          .map(PagedSearchResult.mapping[T])
   )
   .serverLogic { case (searchRequest, jsonFilterRequest, uri)
     myRepository.findPageable(searchRequest)
      .map {
        PagedSearchResult(
          maxSize = maxSize,
          uri = uri,
          jsonFilterRequest = jsonFilterRequest
        )
      }
   }


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the endpoint input and output definitions shown in the issue, especially jsonFilterRequest and extractUri. Determine whether the API can expose request-derived values to output encoding and header generation without passing them through server logic. Done means a settled approach for filtered JSON fields and request-based Link headers.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.