I am writing an API using DRF
to interact with a DynamoDB
table via pynamo-db
. I want to include a retrieve
endpoint that will accept a resource_id
and return the corresponding row from DynamoDB
.
Normally, I would like to be able to call the endpoint like GET /service/resources/{resource_id}/
The problem I am facing is that resource_id
is a composite field of the form {customer_id}-{listing_id}
. I am doing this because this pair uniquely identifies a resource and is the partition_key
of my DynamoDB
table.
customer_id
is a hex field that I have generated for each customer, so I know it is url safe. listing_id
is generated by my customers and it has an arbitrary format. It may - for example - contain a /
, which would mess up my url.
I tried encoding the listing_id
, and in my tests I discovered that %2F
(the url encoding of /
) is still treated by DRF
as a /
, meaning it breaks the url.
I am wondering what is the best practice in this scenario.