grace
10/29/2023, 1:17 PMobject ExampleAppLoader : AppLoader {
override fun invoke(env: Map<String, String>): HttpHandler {
val client = PrintResponse()
.then(ClientFilters.SetBaseUriFrom(Uri.of("<https://pokeapi.co/api/v2/pokemon>")))
.then(JavaHttpClient())
return PrintRequest()
.then(
routes(
"/pokemon" bind client,
.
.
.
)
)
}
}
Initially I thought, if I call my lambda using GET /pokemon, it will call GET https://pokeapi.co/api/v2/pokemon. If I call GET /pokemon/bulbasaur, it will call https://pokeapi.co/api/v2/pokemon/bulbasaur. but I tried to run it locally:
fun main() {
fun runLambdaLocally() {
val app: HttpHandler = ExampleAppLoader(mapOf())
val localLambda = app.asServer(SunHttp(8000)).start()
val response = JavaHttpClient()(
Request(
GET,
"<http://localhost:8000/pokemon>"
)
)
println(response)
localLambda.stop()
}
runLambdaLocally()
}
it's returning 404 error
***** REQUEST: GET: /pokemon *****
GET /pokemon HTTP/1.1
Host: localhost:8000
User-agent: Java-http-client/20.0.2.1
Content-length: 0
<<stream>>
***** RESPONSE 404 to GET: /pokemon *****
HTTP/1.1 404
access-control-allow-origin: *
.
.
.
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=PO2Rj4Y3m7kK7jHlvVdFP%2BnnkmXRuUQ3%2FzRztG2p8WRhUGDtPxWSjsvRlzNGaFsPE40e2prO86z%2BRrE%2BYk%2FjM7OAhCpdWRYHQD00YAxvZFGIKoqGZx2TYqsiAfTm"}],"group":"cf-nel","max_age":604800}
.
.
.
Not Found
HTTP/1.1 404
access-control-allow-origin: *
.
.
.
function-execution-id: yyc7sm5enoc9
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=PO2Rj4Y3m7kK7jHlvVdFP%2BnnkmXRuUQ3%2FzRztG2p8WRhUGDtPxWSjsvRlzNGaFsPE40e2prO86z%2BRrE%2BYk%2FjM7OAhCpdWRYHQD00YAxvZFGIKoqGZx2TYqsiAfTm"}],"group":"cf-nel","max_age":604800}
.
.
.
Not Found
Process finished with exit code 0
what do I have in my routing now ?? thx