Crie uma aplicação que reconheça animais
Uma RESTful API usa a mesma URL mas resposnde de forma diferente dependendo do método HTTP. GenerateHTTPResponse funciona de forma recursiva, assim o cálculo Delayed pode resultar diferentes escolhas de APIFunction para gerenciar métodos HTTP diferentes para implementar uma aplicação web que reporta uma localicação.
Crie um aplicativo simples que reuna os locais onde diferentes tipos de animais foram vistos.
In[1]:=

animallocator = Delayed[
With[{query = HTTPRequestData["Query"]},
Switch[HTTPRequestData["Method"],
"POST",
APIFunction[{"what" -> "Animal",
"where" -> "Location" :> $GeoLocation},
(PutAppend[{#where, #what}, "locations.m"];
"Thank you for your submission.") &],
"GET",
APIFunction[{"zoom" -> Restricted["Integer", {1, 18}] -> 14},
GeoGraphics[
Map[GeoMarker[First[#], Tooltip[Last[#]["Image"], Last[#]],
"Scale" -> Offset[80]] &,
Quiet[Check[ReadList["locations.m"], {}]]],
GeoZoomLevel -> #zoom, ImageSize -> 700] &, "PNG"],
_, HTTPErrorResponse[400]
]
]];
Simule o reporte de algumas imagens de animais.
In[2]:=

GenerateHTTPResponse[
animallocator, <|"Method" -> "POST",
"Query" -> {"what" -> "coyote", "where" -> "40.083449,-88.200732"}|>];
GenerateHTTPResponse[
animallocator, <|"Method" -> "POST",
"Query" -> {"what" -> "buffalo",
"where" -> "40.140722, -88.195257"}|>];
GenerateHTTPResponse[
animallocator, <|"Method" -> "POST",
"Query" -> {"what" -> "beaver", "where" -> "40.063029,-87.9870"}|>];
GenerateHTTPResponse[
animallocator, <|"Method" -> "POST",
"Query" -> {"what" -> "reindeer", "where" -> "40.29778, -88.2023"}|>];
GenerateHTTPResponse[animallocator, <|"Method" -> "POST",
"Query" -> {"what" -> "gopher", "where" -> "40.116420,-88.243383"}|>]
Out[2]=

Simule a obtenção de resultados.
In[3]:=

ImportString[GenerateHTTPResponse[animallocator]["Body"], "PNG"]
Out[3]=
