diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
+## 2.1.4
+
+support http-api-data for url serialization
+
 ## 2.1.3.3
 
 By default explicitly use Int64 for foreign key references.
diff --git a/Database/Persist/TH.hs b/Database/Persist/TH.hs
--- a/Database/Persist/TH.hs
+++ b/Database/Persist/TH.hs
@@ -71,7 +71,8 @@
 import Control.Applicative (pure, (<$>), (<*>))
 import Database.Persist.Sql (sqlType)
 import Data.Proxy (Proxy (Proxy))
-import Web.PathPieces (PathPiece, toPathPiece, fromPathPiece)
+import Web.PathPieces (PathPiece(..))
+import Web.HttpApiData (ToHttpApiData(..), FromHttpApiData(..), parseUrlPieceMaybe)
 import GHC.Generics (Generic)
 import qualified Data.Text.Encoding as TE
 
@@ -669,7 +670,7 @@
 
 
 -- | declare the key type and associated instances
--- a PathPiece instance is only generated for a Key with one field
+-- @'PathPiece'@, @'ToHttpApiData'@ and @'FromHttpApiData'@ instances are only generated for a Key with one field
 mkKeyTypeDec :: MkPersistSettings -> EntityDef -> Q (Dec, [Dec])
 mkKeyTypeDec mps t = do
     (instDecs, i) <-
@@ -683,7 +684,7 @@
                then do pfDec <- pfInstD
                        return (pfDec, [''Show, ''Read, ''Eq, ''Ord, ''Generic])
                 else do
-                    let allInstances = [''Show, ''Read, ''Eq, ''Ord, ''PathPiece, ''PersistField, ''PersistFieldSql, ''ToJSON, ''FromJSON]
+                    let allInstances = [''Show, ''Read, ''Eq, ''Ord, ''PathPiece, ''ToHttpApiData, ''FromHttpApiData, ''PersistField, ''PersistFieldSql, ''ToJSON, ''FromJSON]
                     if customKeyType
                       then return ([], allInstances)
                       else do
@@ -751,6 +752,10 @@
                 compare x y = compare
                     ($(return unKeyE) x)
                     ($(return unKeyE) y)
+             instance ToHttpApiData (BackendKey $(pure backendT)) => ToHttpApiData (Key $(pure recordType)) where
+                toUrlPiece = toUrlPiece . $(return unKeyE)
+             instance FromHttpApiData (BackendKey $(pure backendT)) => FromHttpApiData(Key $(pure recordType)) where
+                parseUrlPiece = fmap $(return keyConE) . parseUrlPiece
              instance PathPiece (BackendKey $(pure backendT)) => PathPiece (Key $(pure recordType)) where
                 toPathPiece = toPathPiece . $(return unKeyE)
                 fromPathPiece = fmap $(return keyConE) . fromPathPiece
diff --git a/persistent-template.cabal b/persistent-template.cabal
--- a/persistent-template.cabal
+++ b/persistent-template.cabal
@@ -1,5 +1,5 @@
 name:            persistent-template
-version:         2.1.3.7
+version:         2.1.4
 license:         MIT
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
@@ -29,6 +29,7 @@
                    , unordered-containers
                    , tagged
                    , path-pieces
+                   , http-api-data            >= 0.2       && < 0.3
                    , ghc-prim
     exposed-modules: Database.Persist.TH
     ghc-options:     -Wall
