For: ``` @Location("/api/customer_book_list/{custo...
# ktor
p
For:
Copy code
@Location("/api/customer_book_list/{customerId}")
data class CustomerBookList(val customerId: String, val type: Int, val update_at: Long)
This curl doesn't resolve:
curl -v <http://localhost:8380/api/customer_book_list/{customerId}?type=0&update_at=987654345>
But if I have one parameter:
Copy code
@Location("/api/customer_purchase_li{customerId}")
data class CustomerPurchaseLi(val customerId: String, val update_at: Long)
a request :
<http://localhost:8380/api/customer_purchase_li{customerId}?update_at=09876543>
does resolve, is there any problem with more than one query parameter being passed to a Location?
d
As documented here: https://ktor.io/features/locations.html#parameters-get It should work. Maybe it is a bug? Let me check
Which ktor version are you using?
p
0.9.3
👍 1
d
I cannot reproduce your issue
Copy code
package com.example

import io.ktor.application.*
import io.ktor.http.*
import io.ktor.locations.*
import io.ktor.response.*
import io.ktor.routing.*

fun main(args: Array<String>): Unit = io.ktor.server.netty.DevelopmentEngine.main(args)

@Location("/location/{name}")
class MyLocation(val name: String, val arg1: Int = 42, val arg2: String = "default")

fun Application.module() {
    install(Locations) {
    }

    routing {
        get<MyLocation> {
            call.respondText("name=${it.name}, arg1=${it.arg1}, arg2=${it.arg2}")
        }
    }
}
does this work for you?
that url work fine for me
if you are not providing default values, those extra arguments are mandatory and otherwise it would return a 404
p
Thanks', its work but int and long stay with the default value and not changed from the url
d
I tried yesterday and worked for me with ints and longs
Whats your url?
p
I tried your url http://localhost:8380/location/test?arg2=hi&amp;arg1=20 and the response was name=test, arg1=42, arg2=hi arg1 stay the default value
d
Uhm
I tried that exactly and changed the value
Dont know whats going on
Can you do some debugging?
p
I tried to change the order of the parameters, and the second param didn't edited
d
talked with you in private to do some debugging
in my case worked both argument orders the same
p
I did some debugging and I see that args2 contains null, why it could be?
d
arg2 is a string and that worked for you as far as you said right? you had problems with arg1
p
no, if I put arg2 last - he contains null, and if I put arg1 last - arg1 contains null
d
uhm, let’s see: which operating system are you using? are you using 0.9.3 downloaded or compiled from source?
which java version are you using?
p
1.8.0_171
d
and OS?
p
4.8.0-53-generic this what you mean?
d
linux?
I tried on a mac
is to try in your operating system to see if I can reproduce your behaviour
since I cannot reproduce it
p
ok
Until now I ran it from terminal, now I check in browser and it works good
d
what? do you mean using curl?
let me try with curl
Copy code
curl "<http://127.0.0.1:8080/location/test?arg2=hi&arg1=20>"
name=test, arg1=20, arg2=hi
are you escaping the url?
because it contains “&”
so maybe your terminal is doing something after the &
in mac for example it not even work at all:
Copy code
curl <http://127.0.0.1:8080/location/test?arg2=hi&arg1=20>
[1] 13871
zsh: no matches found: <http://127.0.0.1:8080/location/test?arg2=hi>
[1]  + 13871 exit 1     curl <http://127.0.0.1:8080/location/test?arg2=hi>
Copy code
➜  /tmp echo 1&echo 2
[1] 13885
1
2
[1]  + 13885 done       echo 1
➜  /tmp echo 1&&echo 2
1
2
http://bashitout.com/2013/05/18/Ampersands-on-the-command-line.html
I guess that if you print the
call.url
you would get something like
/api/customer_purchase_li{customerId}/?arg=1
and no
&arg2=
at all since your terminal thought it was two separate commands.
p
Thank you, I put quotes around my URL and it works good
👍 1
Copy code
curl "<http://localhost:8380/location/test?arg1=20&arg2=hi>"
and not needed a default value
d
perfect