REST related/nested objects URL standard

Question:

if /wallet returns a list a wallets and each wallet has a list of transactions. What is the standard OpenAPI/REST standard?

For example,

http://localhost:8000/api/wallets/ gives me

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "user": 1,
            "address": "3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd",
            "balance": "2627199.00000000"
        }
    ]
}

http://localhost:8000/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/ gives me

{
    "user": 1,
    "address": "3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd",
    "balance": "2627199.00000000"
}

If I wanted to add a transactions list, what is the standard way to form this?

http://localhost:8000/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/transactions ?

http://localhost:8000/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/transactions?offset=100 for pagination

Asked By: Liondancer

||

Answers:

REST doesn’t care what spelling conventions you use for your resources. What it would instead expect is that you have representations of links between resources, along with meta data describing the nature of the link.

So this schema is fine.

/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd
/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd/transactions

And this schema is also fine.

/api/wallets/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd
/api/transactions/3E8ociqZa9mZUSwGdSmAEMAoAxBK3FNDcd

As far as I can tell, OpenAPI also gives you the freedom to design your resource model the way that works best for you (it just tells you one possible way to document the resource model you have selected).

Answered By: VoiceOfUnreason