最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

django rest framework - How do I write a retrieve endpoint when the `id` is not url safe - Stack Overflow

programmeradmin9浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论