'Accept/Content-Type header based processing in Quart and Quart-Schema

Because I am rewriting a legacy app, I cannot change what the clients either send or accept. I have to accept and return JSON, HTML, and an in-house XML-like serialization. They do, fortunately set headers that describe what they are sending and what they accept.

So right now, what I do is have a decoder module and an encoder module with methods that are basically if/elif/else chains. When a route is ready to process/return something, I call the decoder/encoder module with the python object and the header field, which returns the formatted object as a string and the route processes the result or returns Response().

I am wondering if there is a more Quart native way of doing this.

I'm also trying to figure out how to make this work with Quart-Schema. I see from the docs that one can do app.json_encoder = <class> and I suppose I could sub in a different processor there, but it seems application global, there's no way to set it based on what the client sends. Optimally, it would be great if I could just pass the results of a dynamically chosen parser to Quart-Schema and let it do it's thing on python objects.

Thoughts and suggestions welcome. Thanks!



Solution 1:[1]

I removed the z-index style applied to the .wrapper class style. I removed the overflow-x and overflow-y styles applied to the .parent class style. To achieve the goal, I updated the top style applied within the .inner:after class style to -10px and assigned the z-index value to -1 and I got the result.

.wrapper {
  top: 20px;
  display: flex;
  flex: 1;
  align-items: center;
  position: absolute;
  left: 0;
  /* z-index: 3; */
  bottom: 0;
  right: 0;
  height: 50px;
  border-top: 1px solid;
}

.parent {
  display: flex;
  /* overflow-x: auto;   */
  /* overflow-y: hidden; */
  height: 100%;
  flex: 7;
  max-width: 220px;
}

.inner {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  flex-basis: 20%;
  flex-grow: 0;
  min-width: 67px;
}

.inner:after {
    content: "";
    width: 15px;
    height: 15px;
    transform: rotate(45deg);
    background-color: red;
    z-index: -1;
    position: absolute;
    top: -10px;
    left: calc(50% - 10px);
    border: 1px solid;
  }
  
.btn {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 17px;
  width: 100%;
  height: 100%;
  background-color: blue;
  border: none;
  outline: 0;
  cursor: pointer;
  padding-left: 14px;
  border-right: 1px solid;
  color: white;
}
<div class="wrapper">
  <div class="parent"> 
  
    <div class="inner">
      <button class="btn">
        Button1
      </button>
    </div>
    
    <div class="inner">
      <button class="btn">
        Button2
      </button>
    </div>
    
    <div class="inner">
      <button class="btn">
        Button3
      </button>
    </div>
</div>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sercan