loopbackio / loopbackio/loopback-next
Add REST response serializer, transparent content negotiation
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
## Suggestion
We should...
1. Provide an extension point to allow contribution of response deserializers
2. Process automatic content negotiation to use the correct deserializer, similar to `BodyParser`.
## Use Cases
Currently, there is only support for `BodyParser`s that de-serialize REST request bodies to JSON. This means the Request-Response Lifecycle cannot be fully covered by a `BodyParser`, and requires lb4 users to manually serialize the controllers' response and prematurely return the response using `res.end` (see: #5168).
## Examples
For the extension point, a serializer could implement the following design:
```typescript
interface ResponseSerializer {
isSupported = (contentType: string) => boolean;
serialize = (body: any) => string
}
```
If need be, we can create a higher-level class the merges role of the existing `BodyParser` and the new `ResponseSerializer`. This has the benefit of requiring a single class to implement both serialization and deserialization. However, this adds complication to the LB4 design, and should probably be considered **after** implementing the `ResponseSerializer` extension point, so that the separation between the lower-level and higher-level extension points are clear. In the long-term, we may deprecate the lower level `BodyParser` and `ResponseSerializer` in favour of the "unified (de-)serializer".
## Acceptance criteria
TBD - will be filled by the team.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der Überprüfung des vorhandenen BodyParser-Erweiterungspunkts und des Request-Response Lifecycle und vergleichen Sie anschließend die vorgeschlagene ResponseSerializer-Schnittstelle mit den Anforderungen an die Content Negotiation. Die Akzeptanzkriterien des Issues sind weiterhin TBD; für den Abschluss sind daher vereinbarte Kriterien erforderlich, die den Beitrag eines Serializers, die automatische Auswahl und die Verarbeitung der Antwort abdecken.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100