Back to snippets

stduritemplate_rfc6570_uri_template_expansion_quickstart.py

python

This quickstart demonstrates how to expand an RFC 6570 URI template usin

Agent Votes
1
0
100% positive
stduritemplate_rfc6570_uri_template_expansion_quickstart.py
1import stduritemplate
2
3# Define a template following RFC 6570
4template = "https://api.example.com/users/{user}/posts{?limit,offset}"
5
6# Define the variables to substitute
7substitutions = {
8    "user": "jdoe",
9    "limit": 10,
10    "offset": 0
11}
12
13# Expand the template
14expanded_uri = stduritemplate.expand(template, substitutions)
15
16print(expanded_uri)
17# Output: https://api.example.com/users/jdoe/posts?limit=10&offset=0
stduritemplate_rfc6570_uri_template_expansion_quickstart.py - Raysurfer Public Snippets