Custom path separator

23 views
Skip to first unread message

Frédéric Menou

unread,
May 22, 2017, 4:14:24 AM5/22/17
to haskell-servant
Hi guys,

I'm writing a client to some Google APIs, including Google Sheets API.

This action here is causing me some troubles:
As you can see, they capture the id of the object in the URL as usual, but the custom action batchUpdate is specified after a semi-colon that I can't modelize properly with the :> combinator.

As was thinking of either :
  • writing my custom variant of the :> for this case
  • write a custom type to wrap the id and let it be suffixed by some keyword, in this case ':batchUpdate'
Do you have any advice ?

Frédéric

Alp Mestanogullari

unread,
May 22, 2017, 4:23:39 AM5/22/17
to Frédéric Menou, haskell-servant
Hello Frédéric,

I would probably pick the second option, it's the simplest one by far and will get the job done without (to me) feeling like a hack. In case you need to support different "keywords" (i.e not just `batchUpdate`), you could even have something like:

newtype Spreadsheet (action :: Symbol) a = Spreadsheet a

where the 'action' bit would be "batchUpdate" or any other string that you need it to be. This might be overkill for now though if you only need to handle "batchUpdate". Then the logic of extracting the spreadsheetId and checking that it is followed by ":batchUpdate" or more generally by ":" and the keyword specified by "action" with my newtype above, could all be handled as part of the instance for FromHttpApiData

--
You received this message because you are subscribed to the Google Groups "haskell-servant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-servant+unsubscribe@googlegroups.com.
To post to this group, send email to haskell-servant@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/f441edbc-3402-412d-a379-2dea7445a99e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alp Mestanogullari

Frédéric Menou

unread,
May 22, 2017, 5:07:25 AM5/22/17
to haskell-servant, frederi...@gmail.com
OK, thank you,

here what I ended with :

data BatchUpdateCommand = BatchUpdateCommand SpreadsheetId

instance ToHttpApiData BatchUpdateCommand where
  toUrlPiece (BUC sid) = pack sid <> ":batchUpdate"

type API = "spreadsheets"
        :> Capture "spreadsheetId" BatchUpdateCommand
        :> ReqBody '[JSON] BatchUpdate
        :> Post    '[JSON] BatchUpdateResult

batchUpdate' :: BatchUpdateCommand -> BatchUpdate -> ClientM BatchUpdateResult
batchUpdate' = client api

batchUpdate :: SpreadsheetId -> BatchUpdate -> ClientM BatchUpdateResult
batchUpdate sid = batchUpdate' (BUC sid)


Le lundi 22 mai 2017 10:23:39 UTC+2, Alp Mestanogullari a écrit :
Hello Frédéric,

I would probably pick the second option, it's the simplest one by far and will get the job done without (to me) feeling like a hack. In case you need to support different "keywords" (i.e not just `batchUpdate`), you could even have something like:

newtype Spreadsheet (action :: Symbol) a = Spreadsheet a

where the 'action' bit would be "batchUpdate" or any other string that you need it to be. This might be overkill for now though if you only need to handle "batchUpdate". Then the logic of extracting the spreadsheetId and checking that it is followed by ":batchUpdate" or more generally by ":" and the keyword specified by "action" with my newtype above, could all be handled as part of the instance for FromHttpApiData
On Mon, May 22, 2017 at 10:14 AM, Frédéric Menou <frederi...@gmail.com> wrote:
Hi guys,

I'm writing a client to some Google APIs, including Google Sheets API.

This action here is causing me some troubles:
As you can see, they capture the id of the object in the URL as usual, but the custom action batchUpdate is specified after a semi-colon that I can't modelize properly with the :> combinator.

As was thinking of either :
  • writing my custom variant of the :> for this case
  • write a custom type to wrap the id and let it be suffixed by some keyword, in this case ':batchUpdate'
Do you have any advice ?

Frédéric

--
You received this message because you are subscribed to the Google Groups "haskell-servant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-serva...@googlegroups.com.
To post to this group, send email to haskell...@googlegroups.com.



--
Alp Mestanogullari

Alp Mestanogullari

unread,
May 22, 2017, 5:22:51 AM5/22/17
to Frédéric Menou, haskell-servant
Oh right, you only need to ToHttpApiData direction. Looks good to me. I'd probably make BatchUpdateCommand a newtype, but that's just nitpicking :)

To unsubscribe from this group and stop receiving emails from it, send an email to haskell-servant+unsubscribe@googlegroups.com.
To post to this group, send email to haskell-servant@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-servant/9d8668a8-80bf-44fc-a7ac-6940cd085361%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alp Mestanogullari

Frédéric Menou

unread,
May 22, 2017, 5:51:27 AM5/22/17
to haskell-servant, frederi...@gmail.com
Indeed.

Thank you :)



--
Alp Mestanogullari
Reply all
Reply to author
Forward
0 new messages