Skip to content

Add core client methods#10

Merged
jisantuc merged 9 commits intomainfrom
feature/js/core-client-methods
Mar 2, 2021
Merged

Add core client methods#10
jisantuc merged 9 commits intomainfrom
feature/js/core-client-methods

Conversation

@jisantuc
Copy link
Copy Markdown
Owner

@jisantuc jisantuc commented Feb 28, 2021

Overview

This PR adds core client methods and separates Promsie-returning methods (for use in JS) and Aff-returning methods (for use in other PureScript projects).

The remaining methods to implement are:

Checklist

  • Description of PR is in an appropriate section of the changelog (please use chan)
  • Anything JSON-related has a round trip test (skipping tests for CollectionItemsResponse since it's a record of other JSON-able things)

Notes

Testing Instructions

  • fire up a nice stac server
  • create a src/Main.purs like:
module Main where

import Affjax (Error, printError)
import Client.Stac (getCollection, getCollectionItems, getCollections, getConformance, getLandingPage)
import Data.Either (Either(..))
import Data.String.NonEmpty (NonEmptyString, unsafeFromString)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class.Console (info)
import Partial.Unsafe (unsafePartial)
import Prelude (class Show, Unit, bind, show, ($), (<<<), (<>), (>>=))

apiHost :: String
apiHost = "http://localhost:9090"

collectionId :: NonEmptyString
collectionId = unsafePartial $ unsafeFromString "a-nice-collection-id-in-your-api"

showResp :: forall a. Show a => String -> Either Error a -> String
showResp tag (Right _) = show $ "Request successful for " <> tag

showResp tag (Left err) = printError err

main :: Effect Unit
main = do
  collectionsResp <- launchAff_ $ getCollections apiHost >>= (info <<< showResp "collections")
  collectionResp <- launchAff_ $ getCollection apiHost collectionId >>= (info <<< showResp "single collection")
  collectionItemsResp <- launchAff_ $ getCollectionItems apiHost collectionId >>= (info <<< showResp "collection items")
  landingPage <- launchAff_ $ getLandingPage apiHost >>= (info <<< showResp "landing page")
  conformance <- launchAff_ $ getConformance apiHost >>= (info <<< showResp "conformance")
  info "All done!"
  • spago run
  • 😎

Closes #4

Closes #5

@jisantuc jisantuc changed the title [wip] Add core client methods Add core client methods Mar 2, 2021
@jisantuc jisantuc merged commit df86af3 into main Mar 2, 2021
@jisantuc jisantuc deleted the feature/js/core-client-methods branch March 2, 2021 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add client methods for remaining core routes Separate Promise and Aff returning client methods

1 participant