diff --git a/_drafts/til-arrays-elixir.md b/_drafts/til-arrays-elixir.md deleted file mode 100644 index 96b713e..0000000 --- a/_drafts/til-arrays-elixir.md +++ /dev/null @@ -1 +0,0 @@ -some_url?param[]=value1¶m[]=value2 diff --git a/_posts/2020-04-10-til-4.md b/_posts/2020-04-10-til-4.md new file mode 100644 index 0000000..522b5ad --- /dev/null +++ b/_posts/2020-04-10-til-4.md @@ -0,0 +1,31 @@ +--- +post_title: 'Today I Learned #4: Passing array/list parameters to Phoenix controller' +author: dreat +layout: post +published: true +post_date: 2020-04-10 20:00:00 +tags: [til, elixir, phoenix] +categories: [til, new_blog] +--- + +Hello! + +I had curious _incident_ while working. I was to investigate why our API won't work when passed array as url parameter for GET request. + +So, I peeked into the tests and we had test for it. I logged the incoming parameters and Phoenix got an array and worked with it perfectly. So I decided to grab the big guns. Enter curl. + +It was quite funny. My first insting was to create url like this: `some.url?param=[value1,value2]` but it didn't work. Phoenix read this as + +```elixir +%{"param" => "[value1,value2]"} +``` + +and no combination of quotes would make this work. + +To skip some other things I tried - the thing you need to do is to use this + +``` +some_url?param[]=value1¶m[]=value2 +``` + +Phoenix will read all those values as elements of an array (or, in Elixir's context, a list) and it will work as intended.