Adding .self URL instead of id value

Options
I want to make my response JSON more REST with a .self value that contains the URL to the self instead of just the id.  Also, I want to include child values that use an URL instead of a collection of ids.

example:
.../team/1234 responds with:
{
"self": "{api base}/team/1234",
"team_name": "Bad News Bears",
"members": "{api base}/member/team=1234"
}

.../member/team=1234 responds with:
[
 {
  "self": "{api base}/member/9999",
  "first_name":"Fred"
 },
 {
  "self": "{api base}/member/8888",
  "first_name":"Mary"
 },
 {
  "self": "{api base}/member/7777",
  "first_name":"Sam"
 }
 ]

.../member/9999 responds with:
{
"self": "{api base}/member/9999",
  "first_name":"Fred",
  "last_name": "Smith",
  "team": "{api base}/team/1234"
}

So my issue has been how to build out the URLs instead of the values stored in the table.  I thought I could do this simply with an eval and concatenate an environment variable (as the api base), the collection folder (e.g. "/team/"), and the table record (id) within the eval.  However, concatenate is not an option on the filters.

Or if the environment variable is not an option, maybe I could build out a variable before with the full URL and concatenate the id in the eval.  However, again, no concatenate.

So how would you suggest I concatenate a string per record without having to loop the resulting array?  That is the only way I have found so far.

Comments

  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
     major oversight on our part. I could have sworn concat was there for the evals. We will get that fixed asap.
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
     this is now live - you can use the concat filter in your eval now.
  • Tim Tyler
    Tim Tyler Member
    Options
     Thank you, Sean! I built out a looping function to handle this for now. I’ll try out the eval concat on my next endpoint. I’m sure I will need it again soon as I’m following this convention through the app.