{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.APIGateway.CreateBasePathMapping
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new BasePathMapping resource.
module Amazonka.APIGateway.CreateBasePathMapping
  ( -- * Creating a Request
    CreateBasePathMapping (..),
    newCreateBasePathMapping,

    -- * Request Lenses
    createBasePathMapping_stage,
    createBasePathMapping_basePath,
    createBasePathMapping_domainName,
    createBasePathMapping_restApiId,

    -- * Destructuring the Response
    BasePathMapping (..),
    newBasePathMapping,

    -- * Response Lenses
    basePathMapping_stage,
    basePathMapping_basePath,
    basePathMapping_restApiId,
  )
where

import Amazonka.APIGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Requests API Gateway to create a new BasePathMapping resource.
--
-- /See:/ 'newCreateBasePathMapping' smart constructor.
data CreateBasePathMapping = CreateBasePathMapping'
  { -- | The name of the API\'s stage that you want to use for this mapping.
    -- Specify \'(none)\' if you want callers to explicitly specify the stage
    -- name after any base path name.
    CreateBasePathMapping -> Maybe Text
stage :: Prelude.Maybe Prelude.Text,
    -- | The base path name that callers of the API must provide as part of the
    -- URL after the domain name. This value must be unique for all of the
    -- mappings across a single API. Specify \'(none)\' if you do not want
    -- callers to specify a base path name after the domain name.
    CreateBasePathMapping -> Maybe Text
basePath :: Prelude.Maybe Prelude.Text,
    -- | [Required] The domain name of the BasePathMapping resource to create.
    CreateBasePathMapping -> Text
domainName :: Prelude.Text,
    -- | [Required] The string identifier of the associated RestApi.
    CreateBasePathMapping -> Text
restApiId :: Prelude.Text
  }
  deriving (CreateBasePathMapping -> CreateBasePathMapping -> Bool
(CreateBasePathMapping -> CreateBasePathMapping -> Bool)
-> (CreateBasePathMapping -> CreateBasePathMapping -> Bool)
-> Eq CreateBasePathMapping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBasePathMapping -> CreateBasePathMapping -> Bool
$c/= :: CreateBasePathMapping -> CreateBasePathMapping -> Bool
== :: CreateBasePathMapping -> CreateBasePathMapping -> Bool
$c== :: CreateBasePathMapping -> CreateBasePathMapping -> Bool
Prelude.Eq, ReadPrec [CreateBasePathMapping]
ReadPrec CreateBasePathMapping
Int -> ReadS CreateBasePathMapping
ReadS [CreateBasePathMapping]
(Int -> ReadS CreateBasePathMapping)
-> ReadS [CreateBasePathMapping]
-> ReadPrec CreateBasePathMapping
-> ReadPrec [CreateBasePathMapping]
-> Read CreateBasePathMapping
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBasePathMapping]
$creadListPrec :: ReadPrec [CreateBasePathMapping]
readPrec :: ReadPrec CreateBasePathMapping
$creadPrec :: ReadPrec CreateBasePathMapping
readList :: ReadS [CreateBasePathMapping]
$creadList :: ReadS [CreateBasePathMapping]
readsPrec :: Int -> ReadS CreateBasePathMapping
$creadsPrec :: Int -> ReadS CreateBasePathMapping
Prelude.Read, Int -> CreateBasePathMapping -> ShowS
[CreateBasePathMapping] -> ShowS
CreateBasePathMapping -> String
(Int -> CreateBasePathMapping -> ShowS)
-> (CreateBasePathMapping -> String)
-> ([CreateBasePathMapping] -> ShowS)
-> Show CreateBasePathMapping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBasePathMapping] -> ShowS
$cshowList :: [CreateBasePathMapping] -> ShowS
show :: CreateBasePathMapping -> String
$cshow :: CreateBasePathMapping -> String
showsPrec :: Int -> CreateBasePathMapping -> ShowS
$cshowsPrec :: Int -> CreateBasePathMapping -> ShowS
Prelude.Show, (forall x. CreateBasePathMapping -> Rep CreateBasePathMapping x)
-> (forall x. Rep CreateBasePathMapping x -> CreateBasePathMapping)
-> Generic CreateBasePathMapping
forall x. Rep CreateBasePathMapping x -> CreateBasePathMapping
forall x. CreateBasePathMapping -> Rep CreateBasePathMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBasePathMapping x -> CreateBasePathMapping
$cfrom :: forall x. CreateBasePathMapping -> Rep CreateBasePathMapping x
Prelude.Generic)

-- |
-- Create a value of 'CreateBasePathMapping' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'stage', 'createBasePathMapping_stage' - The name of the API\'s stage that you want to use for this mapping.
-- Specify \'(none)\' if you want callers to explicitly specify the stage
-- name after any base path name.
--
-- 'basePath', 'createBasePathMapping_basePath' - The base path name that callers of the API must provide as part of the
-- URL after the domain name. This value must be unique for all of the
-- mappings across a single API. Specify \'(none)\' if you do not want
-- callers to specify a base path name after the domain name.
--
-- 'domainName', 'createBasePathMapping_domainName' - [Required] The domain name of the BasePathMapping resource to create.
--
-- 'restApiId', 'createBasePathMapping_restApiId' - [Required] The string identifier of the associated RestApi.
newCreateBasePathMapping ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'restApiId'
  Prelude.Text ->
  CreateBasePathMapping
newCreateBasePathMapping :: Text -> Text -> CreateBasePathMapping
newCreateBasePathMapping Text
pDomainName_ Text
pRestApiId_ =
  CreateBasePathMapping' :: Maybe Text -> Maybe Text -> Text -> Text -> CreateBasePathMapping
CreateBasePathMapping'
    { $sel:stage:CreateBasePathMapping' :: Maybe Text
stage = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:basePath:CreateBasePathMapping' :: Maybe Text
basePath = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:domainName:CreateBasePathMapping' :: Text
domainName = Text
pDomainName_,
      $sel:restApiId:CreateBasePathMapping' :: Text
restApiId = Text
pRestApiId_
    }

-- | The name of the API\'s stage that you want to use for this mapping.
-- Specify \'(none)\' if you want callers to explicitly specify the stage
-- name after any base path name.
createBasePathMapping_stage :: Lens.Lens' CreateBasePathMapping (Prelude.Maybe Prelude.Text)
createBasePathMapping_stage :: (Maybe Text -> f (Maybe Text))
-> CreateBasePathMapping -> f CreateBasePathMapping
createBasePathMapping_stage = (CreateBasePathMapping -> Maybe Text)
-> (CreateBasePathMapping -> Maybe Text -> CreateBasePathMapping)
-> Lens
     CreateBasePathMapping
     CreateBasePathMapping
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBasePathMapping' {Maybe Text
stage :: Maybe Text
$sel:stage:CreateBasePathMapping' :: CreateBasePathMapping -> Maybe Text
stage} -> Maybe Text
stage) (\s :: CreateBasePathMapping
s@CreateBasePathMapping' {} Maybe Text
a -> CreateBasePathMapping
s {$sel:stage:CreateBasePathMapping' :: Maybe Text
stage = Maybe Text
a} :: CreateBasePathMapping)

-- | The base path name that callers of the API must provide as part of the
-- URL after the domain name. This value must be unique for all of the
-- mappings across a single API. Specify \'(none)\' if you do not want
-- callers to specify a base path name after the domain name.
createBasePathMapping_basePath :: Lens.Lens' CreateBasePathMapping (Prelude.Maybe Prelude.Text)
createBasePathMapping_basePath :: (Maybe Text -> f (Maybe Text))
-> CreateBasePathMapping -> f CreateBasePathMapping
createBasePathMapping_basePath = (CreateBasePathMapping -> Maybe Text)
-> (CreateBasePathMapping -> Maybe Text -> CreateBasePathMapping)
-> Lens
     CreateBasePathMapping
     CreateBasePathMapping
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBasePathMapping' {Maybe Text
basePath :: Maybe Text
$sel:basePath:CreateBasePathMapping' :: CreateBasePathMapping -> Maybe Text
basePath} -> Maybe Text
basePath) (\s :: CreateBasePathMapping
s@CreateBasePathMapping' {} Maybe Text
a -> CreateBasePathMapping
s {$sel:basePath:CreateBasePathMapping' :: Maybe Text
basePath = Maybe Text
a} :: CreateBasePathMapping)

-- | [Required] The domain name of the BasePathMapping resource to create.
createBasePathMapping_domainName :: Lens.Lens' CreateBasePathMapping Prelude.Text
createBasePathMapping_domainName :: (Text -> f Text)
-> CreateBasePathMapping -> f CreateBasePathMapping
createBasePathMapping_domainName = (CreateBasePathMapping -> Text)
-> (CreateBasePathMapping -> Text -> CreateBasePathMapping)
-> Lens CreateBasePathMapping CreateBasePathMapping Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBasePathMapping' {Text
domainName :: Text
$sel:domainName:CreateBasePathMapping' :: CreateBasePathMapping -> Text
domainName} -> Text
domainName) (\s :: CreateBasePathMapping
s@CreateBasePathMapping' {} Text
a -> CreateBasePathMapping
s {$sel:domainName:CreateBasePathMapping' :: Text
domainName = Text
a} :: CreateBasePathMapping)

-- | [Required] The string identifier of the associated RestApi.
createBasePathMapping_restApiId :: Lens.Lens' CreateBasePathMapping Prelude.Text
createBasePathMapping_restApiId :: (Text -> f Text)
-> CreateBasePathMapping -> f CreateBasePathMapping
createBasePathMapping_restApiId = (CreateBasePathMapping -> Text)
-> (CreateBasePathMapping -> Text -> CreateBasePathMapping)
-> Lens CreateBasePathMapping CreateBasePathMapping Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBasePathMapping' {Text
restApiId :: Text
$sel:restApiId:CreateBasePathMapping' :: CreateBasePathMapping -> Text
restApiId} -> Text
restApiId) (\s :: CreateBasePathMapping
s@CreateBasePathMapping' {} Text
a -> CreateBasePathMapping
s {$sel:restApiId:CreateBasePathMapping' :: Text
restApiId = Text
a} :: CreateBasePathMapping)

instance Core.AWSRequest CreateBasePathMapping where
  type
    AWSResponse CreateBasePathMapping =
      BasePathMapping
  request :: CreateBasePathMapping -> Request CreateBasePathMapping
request = Service -> CreateBasePathMapping -> Request CreateBasePathMapping
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateBasePathMapping
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateBasePathMapping)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateBasePathMapping))
-> Logger
-> Service
-> Proxy CreateBasePathMapping
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateBasePathMapping)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String BasePathMapping
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable CreateBasePathMapping

instance Prelude.NFData CreateBasePathMapping

instance Core.ToHeaders CreateBasePathMapping where
  toHeaders :: CreateBasePathMapping -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateBasePathMapping -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Core.ToJSON CreateBasePathMapping where
  toJSON :: CreateBasePathMapping -> Value
toJSON CreateBasePathMapping' {Maybe Text
Text
restApiId :: Text
domainName :: Text
basePath :: Maybe Text
stage :: Maybe Text
$sel:restApiId:CreateBasePathMapping' :: CreateBasePathMapping -> Text
$sel:domainName:CreateBasePathMapping' :: CreateBasePathMapping -> Text
$sel:basePath:CreateBasePathMapping' :: CreateBasePathMapping -> Maybe Text
$sel:stage:CreateBasePathMapping' :: CreateBasePathMapping -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"stage" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
stage,
            (Text
"basePath" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
basePath,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"restApiId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
restApiId)
          ]
      )

instance Core.ToPath CreateBasePathMapping where
  toPath :: CreateBasePathMapping -> ByteString
toPath CreateBasePathMapping' {Maybe Text
Text
restApiId :: Text
domainName :: Text
basePath :: Maybe Text
stage :: Maybe Text
$sel:restApiId:CreateBasePathMapping' :: CreateBasePathMapping -> Text
$sel:domainName:CreateBasePathMapping' :: CreateBasePathMapping -> Text
$sel:basePath:CreateBasePathMapping' :: CreateBasePathMapping -> Maybe Text
$sel:stage:CreateBasePathMapping' :: CreateBasePathMapping -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/domainnames/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
domainName,
        ByteString
"/basepathmappings"
      ]

instance Core.ToQuery CreateBasePathMapping where
  toQuery :: CreateBasePathMapping -> QueryString
toQuery = QueryString -> CreateBasePathMapping -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty