http - How to model a REST API with "POST to PUT redirect"? -
i'm creating rest api backup service, in principle quite simple:
- a user identified
uid
; - files identified
fid
; - to upload file, user
post
s file/backups/<uid>
, location returned - to list files, user
get
s/backups/<uid>
, index offid
s returned - to download file, user picks 1 index,
get
s/backup/<uid>/<fid>
, file returned.
now i'd reduce traffic server delegating up- , downloads service amazon s3.
redirecting downloads not problem, since perform regular redirect (301
or 307
?) generated expiring url.
but uploads? hope have this:
- a user (unaware of s3) starts
post
file server - the server receives headers (not whole file!)
- the server determines place in s3, generates expiring url
put
, redirects it - the client
put
s file url handed server - the server notified of successful upload
the point needs transparent possible users.
i don't think initial post should include entire entity. rather, post must explicitly request "upload bucket" resource created. you'd respond post request 201 created
, location
header pointing new resource file should uploaded.
if upload bucket chosen must depend on specifics of file (file size, type), i'd let client submit metadata in post body.
Comments
Post a Comment