Adding .self URL instead of id value
Options
![Tim Tyler](https://us.v-cdn.net/6037124/user_avatars/2057332.jpg)
Tim Tyler
Member ✭
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.
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
-
major oversight on our part. I could have sworn concat was there for the evals. We will get that fixed asap.
-
this is now live - you can use the concat filter in your eval now.
-
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.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback