digital-asset / daml

The Daml smart contract language
https://www.digitalasset.com/developers
797 stars 199 forks source link

Expose com.digitalasset.http.Endpoints partialfunction returns JsValue directly #3985

Closed lima-da closed 4 years ago

lima-da commented 4 years ago

DABL's API is set up to provide unified JSON request/response as http-json project while providing some extra endpoints and different payloads for its own purposes. To ease the process of DABL reflecting http-json feature update, it is necessary to provide a PartialFunction[HttpRequest, ET[JsValue]]

leo-da commented 4 years ago

HTTP JSON API currently provides: PartialFunction[HttpRequest, Future[HttpResponse]]

However, DABL needs to format HTTP Response differently. DABL upgrades to the latest DAML SDK will be simplified if HTTP JSON API provides: PartialFunction[HttpRequest, ET[JsValue]] for every exposed endpoint.

leo-da commented 4 years ago

@lima-da

  1. Will it be sufficient if HTTP JSON API would allow to override/specify a different formatting rules for HTTP Responses? So you could customize httpResponse(et) call and use the existing PartialFunction[HttpRequest, Future[HttpResponse]]?

  2. Do you plan to use PartialFunction[HttpRequest, ET[JsValue]] in your tests directly? Or do you have any other use cases for JsValue instead of HttpResponse?

lima-da commented 4 years ago

@leo-da

  1. Currently, these partial functions in HTTP JSON are pattern matched by Method and Uri.Path, where in DABL can be different(for example contractLookUp, we are expose as GET with contractId provided in url param), that's another reason why I want them to be directly callable.

  2. For making DABL backwards compatible, DABL does a second parse over the JsValue from your JsValue to another JsValue( the one DABL front-end is depending on) with different shape.