public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "works/search")] HttpRequest req, ILogger log) { string query = req.Query["query"]; var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <SearchRequest>(requestBody); switch (data) { case null when string.IsNullOrEmpty(query): return(new BadRequestObjectResult("You must pass data in the query or body")); case null: data = new SearchRequest { Query = query }; break; } var searchResult = await _worksService.Search(data); return(new OkObjectResult(new WorkListResponse { Works = searchResult, Page = int.Parse(data.Page ?? "1") })); }
// [HttpGet("/works/search")] public async Task <JsonResult> Search([FromQuery] SearchRequest request) { var works = await _worksService.Search(request); return(Json(new WorkListResponse { Works = works, Page = int.Parse(request.Page ?? "1") })); }