Skip to content

Add resource.withParams(dict)#294

Merged
pcantrell merged 4 commits intomasterfrom
with-params
Jul 16, 2019
Merged

Add resource.withParams(dict)#294
pcantrell merged 4 commits intomasterfrom
with-params

Conversation

@pcantrell
Copy link
Copy Markdown
Member

Siesta currently requires you to call withParam for each individual parameter you want to add to a resource:

service.resource()
    .withParam("q": "foo")
    .withParam("page": "7")
    .withParam("order": "created_at")

This PR adds the ability to pass a dictionary of many parameters at once:

service.resource()
    .withParams([
        "q": "foo",
        "page": "7",
        "order": "created_at",
    ])

This has some arguable readability benefit, and can make it easier to build query strings whose keys vary dynamically.

It also has some performance benefit when adding many parameters, since it does not require the creation of intermediate Resource objects at each step — though the benefit is small, on the order of tens of microseconds per param.

Repeatedly altering just a URL is more efficient than repeatedly creating and discarding resources.
@pcantrell pcantrell mentioned this pull request Jul 16, 2019
@pcantrell pcantrell changed the base branch from swift-5 to master July 16, 2019 22:09
@pcantrell pcantrell merged commit 6f1ee59 into master Jul 16, 2019
@pcantrell pcantrell deleted the with-params branch July 16, 2019 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant