Skip to content

Commit

Permalink
Merge pull request #82 from anton-k/release-v2-2
Browse files Browse the repository at this point in the history
Release v-2.1
  • Loading branch information
anton-k authored Nov 29, 2023
2 parents 18a76ff + 07ea48d commit 4bf8304
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/src/00-foreword.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The main features of the mig library are:
* lightweight library
* easy to use. It has simple design on purpose
* expressive DSL to compose servers
* type-safe route handlers and conversions
* type-safe route handlers, URLs and conversions
* handlers are encoded with generic Haskell functions
* built on top of WAI and warp server libraries.
* provides Swagger to your server with one-line of code
Expand Down
46 changes: 45 additions & 1 deletion docs/src/09-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ It turns types like:
Query "a" Int -> Capture "b" Text -> Get Client (Resp Json Text)
```


To types:

```haskell
Expand All @@ -379,6 +378,37 @@ To unwrap `Resp` from response.

## Other utilities

### Type-safe URLs

The type-level function `UrlOf` creates a type-safe `Url` for a given route handler type.
With class `ToUrl` we can generate the URLs for a collection of handlers.

```haskell
class ToUrl a where
toUrl :: Server m -> a
mapUrl :: (Url -> Url) -> a -> a
urlArity :: Int
```

An example of usage.
URL's should be listed in the same order as they appear in the server

```haskell
urls :: Urls
urls = Urls{..}
where
greeting
:| blogPost
:| listPosts
toUrl (server undefined)
```

We can render `Url` to `String`-like type with function:

```haskell
renderUrl :: IsString a => Url -> a
```

### deriving helpers

Sometimes we need to derive too many types at once
Expand Down Expand Up @@ -418,3 +448,17 @@ deriving instance (ToSchema a) => ToSchema (Timed a)
The data type `Timed` has an argument and we have to define the instance
explicitly.

### HTML Links

For usage with template engines that expect JSON as argument for template
there is the type `Link` in the module `Mig.Extra.Html` (also re-exported by all `Html`-related modules):

```haskell
data Link = Link
{ href :: Url
, name :: Text
}
deriving (Generic, ToJSON)
```

Also it has `ToMarkup` instance and rendered as `a`-element link.
4 changes: 2 additions & 2 deletions mig-client/mig-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: mig-client
version: 0.1.0.1
version: 0.1.1.0
synopsis: Build http-clients from API definition for mig servers
description: With this library we can build client functions for HTTP-applications
from the same code as server definition.
Expand Down Expand Up @@ -50,7 +50,7 @@ library
, http-client
, http-media
, http-types
, mig >=0.2.0.1
, mig >=0.2.1.0
, mtl
, text
default-language: GHC2021
4 changes: 2 additions & 2 deletions mig-client/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mig-client
version: 0.1.0.1
version: 0.1.1.0
github: "anton-k/mig"
license: BSD3
author: "Anton Kholomiov"
Expand Down Expand Up @@ -28,7 +28,7 @@ dependencies:
- bytestring
- containers
- http-api-data
- mig >= 0.2.0.1
- mig >= 0.2.1.0
- http-client
- http-media
- mtl
Expand Down
6 changes: 3 additions & 3 deletions mig-extra/mig-extra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: mig-extra
version: 0.1.0.1
version: 0.1.1.0
synopsis: Extra utils for Mig core library
description: Extra utils for mig server library
category: Web
Expand Down Expand Up @@ -62,8 +62,8 @@ library
, http-api-data
, http-media
, http-types
, mig >=0.2.0.1
, mig-client
, mig >=0.2.1.0
, mig-client >=0.1.1.0
, openapi3
, template-haskell
, text
Expand Down
6 changes: 3 additions & 3 deletions mig-extra/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mig-extra
version: 0.1.0.1
version: 0.1.1.0
github: "anton-k/mig"
license: BSD3
author: "Anton Kholomiov"
Expand Down Expand Up @@ -33,7 +33,7 @@ default-extensions:
dependencies:
- base >= 4.7 && < 5
- data-default
- mig >= 0.2.0.1
- mig >= 0.2.1.0
- http-api-data
- blaze-html
- http-types
Expand All @@ -48,7 +48,7 @@ dependencies:
- bytestring
- extra
- exceptions
- mig-client
- mig-client >= 0.1.1.0
- template-haskell
- transformers

Expand Down
30 changes: 30 additions & 0 deletions mig-rio/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Anton Kholomiov (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 2 additions & 1 deletion mig-rio/mig-rio.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ cabal-version: 1.12
name: mig-rio
version: 0.1.0.1
synopsis: Utils to use RIO with mig library
description: Utils to use mig with rio library
description: Utils to use RIO with mig library. Provides instance for HasServer class.
category: Web
homepage: https://github.com/anton-k/mig#readme
bug-reports: https://github.com/anton-k/mig/issues
author: Anton Kholomiov
maintainer: [email protected]
copyright: 2023 Anton Kholomiov
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
Expand Down
7 changes: 2 additions & 5 deletions mig-rio/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ license: BSD3
author: "Anton Kholomiov"
maintainer: "[email protected]"
copyright: "2023 Anton Kholomiov"
license-file: LICENSE

extra-source-files:
- README.md

# Metadata used when publishing your package
synopsis: Utils to use RIO with mig library
description: Utils to use RIO with mig library. Provides instance for HasServer class.
category: Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Utils to use mig with rio library

language: GHC2021

default-extensions:
Expand Down
7 changes: 4 additions & 3 deletions mig-server/mig-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: mig-server
version: 0.1.0.1
version: 0.2.1.0
synopsis: Build lightweight and composable servers
description: With library mig we can build lightweight and composable servers.
There are only couple of combinators to assemble servers from parts.
Expand All @@ -27,6 +27,7 @@ description: With library mig we can build lightweight and composable ser
.
Example of hello world server:
.
> {-# Language OverloadedStrings #-}
> import Mig.Json.IO
>
> -- | We can render the server and run it on port 8085.
Expand Down Expand Up @@ -103,8 +104,8 @@ library
, data-default
, http-api-data
, http-types
, mig >=0.2.0.1
, mig-extra >=0.1.0.1
, mig >=0.2.1.0
, mig-extra >=0.1.1.0
, mig-swagger-ui >=0.1
, mig-wai >=0.1.0.1
, openapi3
Expand Down
7 changes: 4 additions & 3 deletions mig-server/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mig-server
version: 0.1.0.1
version: 0.2.1.0
github: "anton-k/mig"
license: BSD3
author: "Anton Kholomiov"
Expand Down Expand Up @@ -38,6 +38,7 @@ description: |
.
Example of hello world server:
.
> {-# Language OverloadedStrings #-}
> import Mig.Json.IO
>
> -- | We can render the server and run it on port 8085.
Expand Down Expand Up @@ -84,8 +85,8 @@ default-extensions:
dependencies:
- aeson
- base >= 4.7 && < 5
- mig >= 0.2.0.1
- mig-extra >= 0.1.0.1
- mig >= 0.2.1.0
- mig-extra >= 0.1.1.0
- mig-wai >= 0.1.0.1
- http-types
- text
Expand Down
4 changes: 2 additions & 2 deletions mig-wai/mig-wai.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: mig-wai
version: 0.1.0.1
version: 0.1.1.0
synopsis: Render mig-servers as wai-applications
description: Library to render mig-servers as WAI-applications.
category: Web
Expand Down Expand Up @@ -43,7 +43,7 @@ library
, containers
, data-default
, exceptions
, mig >=0.2.0.1
, mig >=0.2.1.0
, text
, wai
default-language: GHC2021
4 changes: 2 additions & 2 deletions mig-wai/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mig-wai
version: 0.1.0.1
version: 0.1.1.0
github: "anton-k/mig"
license: BSD3
author: "Anton Kholomiov"
Expand Down Expand Up @@ -31,7 +31,7 @@ dependencies:
- base >= 4.7 && < 5
- bytestring
- containers
- mig >= 0.2.0.1
- mig >= 0.2.1.0
- text
- wai
- exceptions
Expand Down
2 changes: 1 addition & 1 deletion mig/mig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: mig
version: 0.2.0.1
version: 0.2.1.0
synopsis: Build lightweight and composable servers
description: The Core for the mig server library.
With library mig we can build lightweight and composable servers.
Expand Down
2 changes: 1 addition & 1 deletion mig/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mig
version: 0.2.0.1
version: 0.2.1.0
github: "anton-k/mig"
license: BSD3
author: "Anton Kholomiov"
Expand Down

0 comments on commit 4bf8304

Please sign in to comment.