restful url - REST API: Providing redirect URIs to external services using client app domain -
background
i have restful api accessed through domain http://restapi.com
i have client app using http://restapi.com
. client app has domain http://myapp.com
the way have hateoas setup api presents uris without domain. instead of http://restapi.com/some/resource
, contains links resources /some/resource
. example api json resource below:
{"_links":{"self":{"href":"/some/resource"}}}
the benefit has api doesn't need know client app, , client app has little correct resource api , doesn't have reformat uris in resource. example, in client app, following uri used browser http://myapp.com/some/resource
. when app gets request, needs call api resource , swaps domain i.e. http://restapi.com/some/resource
.
this has been successful for, , allows lot of flexibility have different clients use api knowledge required being initial end point (domain) of api. decouples api client apps.
the problem have run have started using external services (specifically paypal adaptive payments) need provide redirect url cancelled payments , successful payments. example, browser navigates http://myapp.com/payment
. resource returned http://restapi.com/payment
presents link paypal. without going detail, api has ask paypal payment id, can used create link paypal payment e.g. http://paypal.com?payid-123456
. part of creation process requires urls provided redirect on payment cancellation or success. again, don't want go details, when requesting payid paypal, redirect urls sent variables paypal, , guess paypal stores them against specific payid created.
the browser navigates link returned in resource - http://paypal.com?payid-12345
. payment made , paypal uses redirect urls needed redirect app e.g. on successful completion of payment, paypal should redirect http://myapp.com/paymentcomplete
. note: realise not restfully named uri, simplifies building description of problem
problem
the problem have may obvious. need redirect http://myapp.com/paymentcomplete
, but api provides redirect url paypal. has no knowledge of client application. since paypal external service, full url must provided. best api can send http://restapi.com/paymentcomplete
redirect url, if paypal redirects this, resulting response json string (the output format of api) not nicely formatted page of client app.
my question is, way correctly provide redirect url paypal?
one thought had make client application handle creating paypal payid, don't option keep creation of paypal payment id on api side. require every client app provide own implementation, don't want.
the other option though of ask client provide domain in request. request client makes resource link paypal get http://restapi.com/payment
, use post http://restapi.com/payment
client providing domain param. api can use construct correct redirect url. don't idea either seems bit hackish , requires app know must fill in field i.e. human user wouldn't fill domain input in.
additional solutions, or thoughts welcomed.
as had mentioned, paypal external api requires additional parameter , not have control on it. looks client party can provide redirect uri information.
couple of ideas come mind.
the client send redirect uri restapi via header , keeping rest urls intact. grey area , not violation of restful api in opinion. (then again, opinion).
the restapi return response placeholder client fill in before rendering. way api need not know redirect uri , responsibility left client has information.
it nicer if implement option 2 executing couple of lines on javascript code on browser fill-in placeholder. easy. ultimately, 2 end points of transaction aware of redirect uri - browser & paypal.
this alleviates of concerns. job of handling paypal id continue remain api.
Comments
Post a Comment