diff --git a/CHANGELOG.md b/CHANGELOG.md index b421cb4c..033341d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed +- Add a correct content type to POST requests and SearchFilters adjustments [#359](https://github.com/azavea/stac4s/pull/359) ## [0.6.0] - 2021-07-01 ### Added diff --git a/modules/client/js/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala b/modules/client/js/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala index 0fde0605..7375aa8a 100644 --- a/modules/client/js/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala +++ b/modules/client/js/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala @@ -4,6 +4,7 @@ import com.azavea.stac4s.api.client.util.ClientCodecs import com.azavea.stac4s.geometry.Geometry import com.azavea.stac4s.{Bbox, TemporalExtent} +import cats.syntax.option._ import eu.timepit.refined.types.numeric.NonNegInt import io.circe._ import io.circe.refined._ @@ -39,8 +40,8 @@ object SearchFilters extends ClientCodecs { bbox, datetime, intersects, - collectionsOption.getOrElse(Nil), - itemsOption.getOrElse(Nil), + collectionsOption getOrElse Nil, + itemsOption getOrElse Nil, limit, query getOrElse Map.empty, paginationToken @@ -62,10 +63,10 @@ object SearchFilters extends ClientCodecs { filters.bbox, filters.datetime, filters.intersects, - filters.collections, - filters.items, + filters.collections.some.filter(_.nonEmpty), + filters.items.some.filter(_.nonEmpty), filters.limit, - filters.query, + filters.query.some.filter(_.nonEmpty), filters.next ) ) diff --git a/modules/client/jvm/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala b/modules/client/jvm/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala index f64088d6..ce65366d 100644 --- a/modules/client/jvm/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala +++ b/modules/client/jvm/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala @@ -3,6 +3,7 @@ package com.azavea.stac4s.api.client import com.azavea.stac4s.api.client.util.ClientCodecs import com.azavea.stac4s.{Bbox, TemporalExtent} +import cats.syntax.option._ import eu.timepit.refined.types.numeric.NonNegInt import geotrellis.vector.{io => _, _} import io.circe._ @@ -39,8 +40,8 @@ object SearchFilters extends ClientCodecs { bbox, datetime, intersects, - collectionsOption.getOrElse(Nil), - itemsOption.getOrElse(Nil), + collectionsOption getOrElse Nil, + itemsOption getOrElse Nil, limit, query getOrElse Map.empty, paginationToken @@ -62,10 +63,10 @@ object SearchFilters extends ClientCodecs { filters.bbox, filters.datetime, filters.intersects, - filters.collections, - filters.items, + filters.collections.some.filter(_.nonEmpty), + filters.items.some.filter(_.nonEmpty), filters.limit, - filters.query, + filters.query.some.filter(_.nonEmpty), filters.next ) ) diff --git a/modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/SttpStacClientF.scala b/modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/SttpStacClientF.scala index c64feac9..8234fd63 100644 --- a/modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/SttpStacClientF.scala +++ b/modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/SttpStacClientF.scala @@ -17,7 +17,7 @@ import io.circe.{Encoder, Json, JsonObject} import monocle.Lens import sttp.client3.circe.asJson import sttp.client3.{Response, SttpBackend, UriContext, basicRequest} -import sttp.model.Uri +import sttp.model.{MediaType, Uri} case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]]: Encoder]( client: SttpBackend[F, Any], @@ -40,7 +40,13 @@ case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]] Stream .unfoldLoopEval((baseUri.addPath("search"), initialBody)) { case (link, request) => client - .send(basicRequest.body(request.noSpaces).post(link).response(asJson[Json])) + .send( + basicRequest + .post(link) + .contentType(MediaType.ApplicationJson) + .body(request.deepDropNullValues.noSpaces) + .response(asJson[Json]) + ) .flatMap { response => val items = response.stacItems val next = response.nextLink.nested.map(_ -> noPaginationBody).value @@ -77,6 +83,7 @@ case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]] .send( basicRequest .post(baseUri.addPath("collections")) + .contentType(MediaType.ApplicationJson) .body(collection.asJson.noSpaces) .response(asJson[StacCollection]) ) @@ -109,6 +116,7 @@ case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]] .send( basicRequest .post(baseUri.addPath("collections", collectionId.value, "items")) + .contentType(MediaType.ApplicationJson) .body(item.asJson.noSpaces) .response(asJson[StacItem]) )