avers-api 0.0.5 → 0.0.17.0
raw patch · 3 files changed
+161/−129 lines, 3 filesdep ~aesondep ~bytestringdep ~cookiePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: aeson, bytestring, cookie, http-api-data, servant, text, time, vector
API changes (from Hackage documentation)
- Avers.API: type AversAccountAPI = "signup" :> (ReqBody '[JSON] SignupBody :> Post '[JSON] SignupResponse)
- Avers.API: type AversBlobAPI = ("blobs" :> (Header "Content-Type" Text :> (ReqBody '[OctetStream] ByteString :> Post '[JSON] UploadBlobResponse))) :<|> (("blobs" :> (Capture "blobId" BlobId :> Get '[JSON] LookupBlobResponse)) :<|> ("blobs" :> (Capture "blobId" BlobId :> ("content" :> Get '[OctetStream] (Headers '[Header "Content-Type" Text] ByteString)))))
- Avers.API: type AversCoreAPI = ("objects" :> (Credentials :> (ReqBody '[JSON] CreateObjectBody :> Post '[JSON] CreateObjectResponse))) :<|> (("objects" :> (Capture "objId" ObjId :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupObjectResponse))))) :<|> (("objects" :> (Capture "objId" ObjId :> (Credentials :> (ReqBody '[JSON] PatchObjectBody :> Patch '[JSON] PatchObjectResponse)))) :<|> (("objects" :> (Capture "objId" ObjId :> (Credentials :> Delete '[JSON] ()))) :<|> (("objects" :> (Capture "objId" ObjId :> ("patches" :> (Capture "revId" RevId :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupPatchResponse))))))) :<|> (("objects" :> (Capture "objId" ObjId :> ("changes" :> (Credentials :> Raw)))) :<|> (("objects" :> (Capture "objId" ObjId :> ("releases" :> (Credentials :> (ReqBody '[JSON] CreateReleaseBody :> Post '[JSON] CreateReleaseResponse))))) :<|> (("objects" :> (Capture "objId" ObjId :> ("releases" :> (Capture "revId" RevId :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupReleaseResponse))))))) :<|> (("objects" :> (Capture "objId" ObjId :> ("releases" :> ("_latest" :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupLatestReleaseResponse))))))) :<|> (("feed" :> (Credentials :> Raw)) :<|> ("secret" :> (Credentials :> (ReqBody '[JSON] ChangeSecretBody :> Post '[] ()))))))))))))
- Avers.API: type AversSessionAPI = ("session" :> (ReqBody '[JSON] CreateSessionBody :> Post '[JSON] (Headers '[Header "Set-Cookie" SetCookie] CreateSessionResponse))) :<|> (("session" :> (SessionId :> Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie] LookupSessionResponse))) :<|> ("session" :> (SessionId :> Delete '[JSON] (Headers '[Header "Set-Cookie" SetCookie] ()))))
+ Avers.API: BlobContent :: ByteString -> BlobContent
+ Avers.API: [lbrContentType] :: LookupBlobResponse -> !Text
+ Avers.API: [lbrId] :: LookupBlobResponse -> !BlobId
+ Avers.API: [lbrSize] :: LookupBlobResponse -> !Int
+ Avers.API: [ubrContentType] :: UploadBlobResponse -> !Text
+ Avers.API: [ubrId] :: UploadBlobResponse -> !BlobId
+ Avers.API: [ubrSize] :: UploadBlobResponse -> !Int
+ Avers.API: newtype BlobContent
+ Avers.API: type AversAPI = CreateObject :<|> (LookupObject :<|> (PatchObject :<|> (DeleteObject :<|> (LookupPatch :<|> (ObjectChanges :<|> (CreateRelease :<|> (LookupRelease :<|> (LookupLatestRelease :<|> (Feed :<|> (ChangeSecret :<|> (CreateSession :<|> (LookupSession :<|> (DeleteSession :<|> (UploadBlob :<|> (LookupBlob :<|> (LookupBlobContent :<|> Signup))))))))))))))))
+ Avers.API: type ChangeSecret = "secret" :> (Credentials :> (ReqBody '[JSON] ChangeSecretBody :> Post '[JSON] ()))
+ Avers.API: type CreateObject = "objects" :> (Credentials :> (ReqBody '[JSON] CreateObjectBody :> Post '[JSON] CreateObjectResponse))
+ Avers.API: type CreateRelease = "objects" :> (Capture "objId" ObjId :> ("releases" :> (Credentials :> (ReqBody '[JSON] CreateReleaseBody :> Post '[JSON] CreateReleaseResponse))))
+ Avers.API: type CreateSession = "session" :> (ReqBody '[JSON] CreateSessionBody :> Post '[JSON] (Headers '[Header "Set-Cookie" SetCookie] CreateSessionResponse))
+ Avers.API: type DeleteObject = "objects" :> (Capture "objId" ObjId :> (Credentials :> Delete '[JSON] ()))
+ Avers.API: type DeleteSession = "session" :> (SessionId :> Delete '[JSON] (Headers '[Header "Set-Cookie" SetCookie] ()))
+ Avers.API: type Feed = "feed" :> (Credentials :> Raw)
+ Avers.API: type LookupBlob = "blobs" :> (Capture "blobId" BlobId :> (Credentials :> Get '[JSON] LookupBlobResponse))
+ Avers.API: type LookupBlobContent = "blobs" :> (Capture "blobId" BlobId :> ("content" :> (Credentials :> Get '[OctetStream] (Headers '[Header "Content-Type" Text] BlobContent))))
+ Avers.API: type LookupLatestRelease = "objects" :> (Capture "objId" ObjId :> ("releases" :> ("_latest" :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupLatestReleaseResponse))))))
+ Avers.API: type LookupObject = "objects" :> (Capture "objId" ObjId :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupObjectResponse))))
+ Avers.API: type LookupPatch = "objects" :> (Capture "objId" ObjId :> ("patches" :> (Capture "revId" RevId :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupPatchResponse))))))
+ Avers.API: type LookupRelease = "objects" :> (Capture "objId" ObjId :> ("releases" :> (Capture "revId" RevId :> (Credentials :> (CacheValidationToken :> Get '[JSON] (Cacheable LookupReleaseResponse))))))
+ Avers.API: type LookupSession = "session" :> (SessionId :> Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie] LookupSessionResponse))
+ Avers.API: type ObjectChanges = "objects" :> (Capture "objId" ObjId :> ("changes" :> (Credentials :> Raw)))
+ Avers.API: type PatchObject = "objects" :> (Capture "objId" ObjId :> (Credentials :> (ReqBody '[JSON] PatchObjectBody :> Patch '[JSON] PatchObjectResponse)))
+ Avers.API: type Signup = "signup" :> (ReqBody '[JSON] SignupBody :> Post '[JSON] SignupResponse)
+ Avers.API: type UploadBlob = "blobs" :> (Credentials :> (Header "Content-Type" Text :> (ReqBody '[OctetStream] BlobContent :> Post '[JSON] UploadBlobResponse)))
- Avers.API: LookupBlobResponse :: LookupBlobResponse
+ Avers.API: LookupBlobResponse :: !BlobId -> !Int -> !Text -> LookupBlobResponse
- Avers.API: UploadBlobResponse :: UploadBlobResponse
+ Avers.API: UploadBlobResponse :: !BlobId -> !Int -> !Text -> UploadBlobResponse
Files
- avers-api.cabal +36/−37
- src/Avers/API.hs +90/−88
- src/Avers/API/Types.hs +35/−4
avers-api.cabal view
@@ -1,42 +1,41 @@-name: avers-api-version: 0.0.5-synopsis: Types describing the core and extended Avers APIs-description: See README-homepage: http://github.com/wereHamster/avers-api-license: MIT-license-file: LICENSE-author: Tomas Carnecky-maintainer: tomas.carnecky@gmail.com-copyright: 2016 Tomas Carnecky-category: Avers-build-type: Simple-cabal-version: >=1.10+name: avers-api+version: 0.0.17.0+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE+copyright: 2016 Tomas Carnecky+maintainer: tomas.carnecky@gmail.com+homepage: http://github.com/wereHamster/avers-api+synopsis: Types describing the core and extended Avers APIs+description:+ See README+category: Avers+author: Tomas Carnecky source-repository head- type: git- location: https://github.com/wereHamster/avers-api+ type: git+ location: https://github.com/wereHamster/avers-api library- default-language: Haskell2010- hs-source-dirs: src- ghc-options: -Wall-- exposed-modules:- Avers.API-- other-modules:- Avers.API.Types- , Avers.API.Instances- , Avers.API.Credentials+ exposed-modules:+ Avers.API+ build-depends:+ base >=4.7 && <5,+ aeson >=1.0.2.0 && <1.1,+ avers -any,+ bytestring >=0.10.8.1 && <0.11,+ cookie >=0.4.2.1 && <0.5,+ http-api-data >=0.3.2 && <0.4,+ servant >=0.9.0.1 && <0.10,+ text >=1.2.2.1 && <1.3,+ time >=1.6.0.1 && <1.7,+ vector >=0.11.0.0 && <0.12+ default-language: Haskell2010+ hs-source-dirs: src+ other-modules:+ Avers.API.Types+ Avers.API.Instances+ Avers.API.Credentials+ ghc-options: -Wall - build-depends:- base >= 4.7 && < 5- , aeson- , avers- , bytestring- , cookie- , http-api-data- , servant- , text- , time- , vector
src/Avers/API.hs view
@@ -4,8 +4,27 @@ {-# LANGUAGE TypeOperators #-} module Avers.API- ( AversCoreAPI, AversSessionAPI, AversBlobAPI, AversAccountAPI+ ( AversAPI + , CreateObject+ , LookupObject+ , PatchObject+ , DeleteObject+ , LookupPatch+ , ObjectChanges+ , CreateRelease+ , LookupRelease+ , LookupLatestRelease+ , Feed+ , ChangeSecret+ , CreateSession+ , LookupSession+ , DeleteSession+ , UploadBlob+ , LookupBlob+ , LookupBlobContent+ , Signup+ , CacheValidationToken, Cacheable , module Avers.API.Types@@ -14,7 +33,6 @@ import Data.Text (Text)-import Data.ByteString (ByteString) import Avers.Types (ObjId, RevId, BlobId, SessionId) @@ -38,6 +56,7 @@ -- -- <path> including any captured components -- <credentials>+-- <headers> -- <cache validation token> -- <request body> -- <method and response>@@ -57,150 +76,133 @@ ----------------------------------------------------------------------------------- | The Core API to manipulate objects, patches, releases etc.+-- | The complete Avers API -type AversCoreAPI - ------------------------------------------------------------------------------- -- CreateObject- = "objects"+type CreateObject+ = "objects" :> Credentials :> ReqBody '[JSON] CreateObjectBody :> Post '[JSON] CreateObjectResponse - ------------------------------------------------------------------------------- -- LookupObject- :<|> "objects" :> Capture "objId" ObjId+type LookupObject+ = "objects" :> Capture "objId" ObjId :> Credentials :> CacheValidationToken :> Get '[JSON] (Cacheable LookupObjectResponse) - ------------------------------------------------------------------------------- -- PatchObject- :<|> "objects" :> Capture "objId" ObjId+type PatchObject+ = "objects" :> Capture "objId" ObjId :> Credentials :> ReqBody '[JSON] PatchObjectBody :> Patch '[JSON] PatchObjectResponse - ------------------------------------------------------------------------------- -- DeleteObject- :<|> "objects" :> Capture "objId" ObjId+type DeleteObject+ = "objects" :> Capture "objId" ObjId :> Credentials :> Delete '[JSON] () - ------------------------------------------------------------------------------- -- LookupPatch- :<|> "objects" :> Capture "objId" ObjId :> "patches" :> Capture "revId" RevId+type LookupPatch+ = "objects" :> Capture "objId" ObjId :> "patches" :> Capture "revId" RevId :> Credentials :> CacheValidationToken :> Get '[JSON] (Cacheable LookupPatchResponse) - ------------------------------------------------------------------------------- -- ObjectChanges- :<|> "objects" :> Capture "objId" ObjId :> "changes"+type ObjectChanges+ = "objects" :> Capture "objId" ObjId :> "changes" :> Credentials :> Raw -- WebSocket, stream of ObjectChangeNotification - ------------------------------------------------------------------------------- -- CreateRelease- :<|> "objects" :> Capture "objId" ObjId :> "releases"+type CreateRelease+ = "objects" :> Capture "objId" ObjId :> "releases" :> Credentials :> ReqBody '[JSON] CreateReleaseBody :> Post '[JSON] CreateReleaseResponse - ------------------------------------------------------------------------------- -- LookupRelease- :<|> "objects" :> Capture "objId" ObjId :> "releases" :> Capture "revId" RevId+type LookupRelease+ = "objects" :> Capture "objId" ObjId :> "releases" :> Capture "revId" RevId :> Credentials :> CacheValidationToken :> Get '[JSON] (Cacheable LookupReleaseResponse) - ------------------------------------------------------------------------------- -- LookupLatestRelease- :<|> "objects" :> Capture "objId" ObjId :> "releases" :> "_latest"+type LookupLatestRelease+ = "objects" :> Capture "objId" ObjId :> "releases" :> "_latest" :> Credentials :> CacheValidationToken :> Get '[JSON] (Cacheable LookupLatestReleaseResponse) - ------------------------------------------------------------------------------- -- Feed- :<|> "feed"+type Feed+ = "feed" :> Credentials :> Raw -- WebSocket, stream of 'Change' objects - ------------------------------------------------------------------------------- -- ChangeSecret- :<|> "secret"+type ChangeSecret+ = "secret" :> Credentials :> ReqBody '[JSON] ChangeSecretBody- :> Post '[] ()--------------------------------------------------------------------------------------- | API to create and maintain sessions. Also contains API to--- change the secret, which is part of the session code.--type AversSessionAPI+ :> Post '[JSON] () - ------------------------------------------------------------------------------- -- CreateSession- = "session"+type CreateSession+ = "session" :> ReqBody '[JSON] CreateSessionBody :> Post '[JSON] (Headers '[Header "Set-Cookie" SetCookie] CreateSessionResponse) - ------------------------------------------------------------------------------- -- LookupSession- :<|> "session"+type LookupSession+ = "session" :> SessionId :> Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie] LookupSessionResponse) - ------------------------------------------------------------------------------- -- DeleteSession- :<|> "session"+type DeleteSession+ = "session" :> SessionId :> Delete '[JSON] (Headers '[Header "Set-Cookie" SetCookie] ()) -------------------------------------------------------------------------------------- | API to manange blobs--type AversBlobAPI-- ------------------------------------------------------------------------------- -- UploadBlob- = "blobs"+type UploadBlob+ = "blobs"+ :> Credentials :> Header "Content-Type" Text- :> ReqBody '[OctetStream] ByteString+ :> ReqBody '[OctetStream] BlobContent :> Post '[JSON] UploadBlobResponse - ------------------------------------------------------------------------------- -- LookupBlob- :<|> "blobs" :> Capture "blobId" BlobId+type LookupBlob+ = "blobs" :> Capture "blobId" BlobId+ :> Credentials :> Get '[JSON] LookupBlobResponse - ------------------------------------------------------------------------------- -- BlobContent- :<|> "blobs" :> Capture "blobId" BlobId :> "content"- :> Get '[OctetStream] (Headers '[Header "Content-Type" Text] ByteString)+type LookupBlobContent+ = "blobs" :> Capture "blobId" BlobId :> "content"+ :> Credentials+ :> Get '[OctetStream] (Headers '[Header "Content-Type" Text] BlobContent) +-- | Similar to CreateObject but no authorization is required. Instead,+-- a different mechanism is used to ensure that the client is allowed+-- to execute the action (eg. an captcha).+type Signup+ = "signup"+ :> ReqBody '[JSON] SignupBody+ :> Post '[JSON] SignupResponse ------------------------------------------ | API to manage accounts. These are optional and not really part of--- Avers, but many applications do have a concept of a user or account,--- some person which is using the API. -type AversAccountAPI-- ------------------------------------------------------------------------------- -- Signup.- --- -- Similar to CreateObject but no authorization is required. Instead,- -- a different mechanism is used to ensure that the client is allowed- -- to execute the action (eg. an captcha).+--------------------------------------------------------------------------------+-- | The complete Avers API as a data type. - = "signup"- :> ReqBody '[JSON] SignupBody- :> Post '[JSON] SignupResponse+type AversAPI+ = CreateObject+ :<|> LookupObject+ :<|> PatchObject+ :<|> DeleteObject+ :<|> LookupPatch+ :<|> ObjectChanges+ :<|> CreateRelease+ :<|> LookupRelease+ :<|> LookupLatestRelease+ :<|> Feed+ :<|> ChangeSecret+ :<|> CreateSession+ :<|> LookupSession+ :<|> DeleteSession+ :<|> UploadBlob+ :<|> LookupBlob+ :<|> LookupBlobContent+ :<|> Signup
src/Avers/API/Types.hs view
@@ -1,15 +1,20 @@-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-} + module Avers.API.Types where import GHC.Generics +import Data.ByteString (ByteString)+import Data.ByteString.Lazy (toStrict, fromStrict) import Data.Text (Text) import Data.Aeson as A import Data.Vector as V import Data.Time import Avers+import Servant.API (MimeRender(..), MimeUnrender(..), OctetStream) @@ -250,18 +255,44 @@ -------------------------------------------------------------------------------- -- UploadBlob +newtype BlobContent = BlobContent ByteString++instance MimeUnrender OctetStream BlobContent where+ mimeUnrender _ bs = Right (BlobContent $ toStrict bs)++instance MimeRender OctetStream BlobContent where+ mimeRender _ (BlobContent bs) = fromStrict bs+ data UploadBlobResponse = UploadBlobResponse- {+ { ubrId :: !BlobId+ , ubrSize :: !Int+ , ubrContentType :: !Text } deriving (Generic) +instance ToJSON UploadBlobResponse where+ toJSON x = object+ [ "id" .= ubrId x+ , "size" .= ubrSize x+ , "contentType" .= ubrContentType x+ ] + -------------------------------------------------------------------------------- -- LookupBlob data LookupBlobResponse = LookupBlobResponse- {+ { lbrId :: !BlobId+ , lbrSize :: !Int+ , lbrContentType :: !Text } deriving (Generic)++instance ToJSON LookupBlobResponse where+ toJSON x = object+ [ "id" .= lbrId x+ , "size" .= lbrSize x+ , "contentType" .= lbrContentType x+ ]