plainblack / ving

An opinionated web services starter for Nuxt3 that provides REST and per-field privileges out of the box.
https://plainblack.github.io/ving/
58 stars 7 forks source link

rest links #29

Closed rizen closed 5 months ago

rizen commented 6 months ago

switch to using links like this in the response as it would work for object relationships and human links alike

'links' => [ { 'method' => 'GET', 'rel' => 'self', 'href' => 'https://api.sandbox.paypal.com/v2/checkout/orders/3L991810LA4523710' }, { 'href' => 'https://www.sandbox.paypal.com/checkoutnow?token=3L991810LA4523710', 'rel' => 'approve', 'method' => 'GET' }, { 'method' => 'PATCH', 'rel' => 'update', 'href' => 'https://api.sandbox.paypal.com/v2/checkout/orders/3L991810LA4523710' }, { 'method' => 'POST', 'rel' => 'capture', 'href' => 'https://api.sandbox.paypal.com/v2/checkout/orders/3L991810LA4523710/capture' } ]

rizen commented 5 months ago

variants we considered

"links" : {
  "GET" : {
     "base" : "http://localhost:3000/api/user",
     "self" : "http://localhost:3000/api/user/xxx",
     "apikeys" : "http://localhost:3000/api/user/xxx/apikeys", 
     "avatar" : "http://someavatarsite.org/user/xxx.svg",
   },
   "POST" : {
      "base" : "http://localhost:3000/api/user",
   },
   "PUT" : {
     "self" : "http://localhost:3000/api/user/xxx",
   },
   "DELETE" : {
      "self" : "http://localhost:3000/api/user/xxx",
   }
   ...
}
"links" : {
     "http://localhost:3000/api/user" : ['GET','POST','PUT','DELETE'],
     "http://localhost:3000/api/user/xxx" : ['GET','PUT','DELETE'],
     "http://localhost:3000/api/user/xxx/apikeys"  : ['GET'], 
     "http://someavatarsite.org/user/xxx.svg"  : ['GET'],
   ...
}
"links" : {
  "base" : {
    "href" : "http://localhost:3000/api/user",
    "methods" : ['GET','POST']
  },
  "self" : {
    "href" : "http://localhost:3000/api/user/xxx",
    "methods" : ['GET','POST']
  },
 "avatar" : {
    "href" : "http://someavatarsite.org/user/xxx.svg",
    "methods" : ['GET']
  }, 
  "apikeys" : {
    "href" : "http://localhost:3000/api/user/xxx/apikeys",
    "methods" : ['GET']
  },
}
rizen commented 5 months ago

Current version is so light weight though:

"links" : {
  "base" : "/api/user",
  "self" : "/api/user/xxx",
  "apikeys" : "/api/user/xxx/apikeys", 
   ...
}