# URI.encode single parameter

**URL:** <https://forum.crystal-lang.org/t/uri-encode-single-parameter/1574>\
**Category:** Help & Support\
**Created:** [January 1, 2020, 5:40pm UTC](https://forum.crystal-lang.org/t/uri-encode-single-parameter/1574 "2020-01-01T17:40:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/rogerdpack/32/117_2.png) [@rogerdpack](https://forum.crystal-lang.org/u/rogerdpack)\
**Post date:** [January 1, 2020, 5:40pm UTC](https://forum.crystal-lang.org/t/uri-encode-single-parameter/1574/1 "2020-01-01T17:40:55Z")

</div>

Hello.  
I was attempting to use the new `URI.encode` method.  
I used to be able to call this:

`URI.escape("some string", true)`

but replacing with `URI.encode("some string", true)` I get this:

```auto
URI.encode("peter + paul", true)

In test2.cr:4:5

 4 | URI.encode("peter + paul", true)
         ^-----
Error: no overload matches 'URI.encode' with types String, Bool

Overloads are:
 - URI.encode(string : String, io : IO, *, space_to_plus : Bool = false)
 - URI.encode(string : String, *, space_to_plus : Bool = false)
 - URI.encode(string : String, io : IO, space_to_plus : Bool = false, &block)

```

but this works:

`URI.encode("peter + paul", space_to_plus: true) # => "peter+%2B+paul"`

Am I missing something fundamental here? Should it be callable with only two parameters? Thanks!

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [January 1, 2020, 5:55pm UTC](https://forum.crystal-lang.org/t/uri-encode-single-parameter/1574/2 "2020-01-01T17:55:06Z")

</div>

If you look at the overloads, the `*` means that any arguments after it must be named arguments; hence why your first example doesn’t work while the second does.

See [https://crystal-lang.org/reference/syntax\_and\_semantics/default\_values\_named\_arguments\_splats\_tuples\_and\_overloading.html#how-call-arguments-are-matched-to-method-arguments](https://crystal-lang.org/reference/syntax_and_semantics/default_values_named_arguments_splats_tuples_and_overloading.html#how-call-arguments-are-matched-to-method-arguments).

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [January 1, 2020, 10:34pm UTC](https://forum.crystal-lang.org/t/uri-encode-single-parameter/1574/3 "2020-01-01T22:34:10Z")

</div>

When these methods were refactored and renamed in [#7997](https://github.com/crystal-lang/crystal/pull/7997), `space_to_plus` became a named-only argument. This is intended to better express the intention at the call site: When reading `URI.encode(string, true)`, the meaning of `true` argument is not obvious. Instead, the reader might wonder why such a method needs a configuration argument at all. Requiring to pass it as a named argument called `space_to_plus` makes its purpose clear. Since renaming the method broke the API anyway, it was a good opportunity to improve the configuration argument as well.
