Personal tools

HaXR

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
 
m (add myself as maintainer)
 
(4 intermediate revisions by one user not shown)
Line 5: Line 5:
 
and server applications in [http://www.haskell.org/ Haskell].
 
and server applications in [http://www.haskell.org/ Haskell].
 
</p>
 
</p>
 
<p>HaXR consists of two packages: <tt>haxr</tt> and <tt>haxr-th</tt>.
 
The latter package contains the Template Haskell code used for automatically
 
deriving XML-RPC struct representations for Haskell records.</p>
 
  
 
<p>Christopher Milton came up with the HaXR name, thanks!</p>
 
<p>Christopher Milton came up with the HaXR name, thanks!</p>
Line 15: Line 11:
  
 
<h3>Examples</h3>
 
<h3>Examples</h3>
 +
 +
 +
<p>Example are available in the [http://code.haskell.org/haxr/examples/ <tt>examples/</tt>] folder in the darcs repository. Here we talk about
 +
a couple of them.
 +
</p>
 +
  
 
<h4>Server</h4>
 
<h4>Server</h4>
Line 21: Line 23:
 
integers and returns their sum.</p>
 
integers and returns their sum.</p>
  
<pre>
+
<haskell>
 
import Network.XmlRpc.Server
 
import Network.XmlRpc.Server
  
add :: Int -&gt; Int -&gt; IO Int
+
add :: Int -> Int -> IO Int
 
add x y = return (x + y)
 
add x y = return (x + y)
  
 
main = cgiXmlRpcServer [("examples.add", fun add)]
 
main = cgiXmlRpcServer [("examples.add", fun add)]
</pre>
+
</haskell>
  
 
<p>Note: the argument to <tt>fun</tt> can be a function that
 
<p>Note: the argument to <tt>fun</tt> can be a function that
Line 38: Line 40:
 
above and prints the result.</p>
 
above and prints the result.</p>
  
<pre>
+
<haskell>
 
import Network.XmlRpc.Client
 
import Network.XmlRpc.Client
  
Line 49: Line 51:
 
       let x = 4
 
       let x = 4
 
  y = 7
 
  y = 7
       z &lt;- add server x y
+
       z <- add server x y
 
       putStrLn (show x ++ " + " ++ show y ++ " = " ++ show z)
 
       putStrLn (show x ++ " + " ++ show y ++ " = " ++ show z)
</pre>
+
</haskell>
  
 
<p>Note: the function returned by <tt>remote</tt>  
 
<p>Note: the function returned by <tt>remote</tt>  
Line 60: Line 62:
 
<p>Have a look at <tt>[http://code.haskell.org/haxr/examples/Person.hs examples/Person.hs]</tt> for an example of how  
 
<p>Have a look at <tt>[http://code.haskell.org/haxr/examples/Person.hs examples/Person.hs]</tt> for an example of how  
 
to use heterogeneous structs.  
 
to use heterogeneous structs.  
[http://code.haskell.org/haxr/haxr-th/examples/PersonTH.hs <tt>haxr-th/examples/PersonTH.hs</tt>]
+
[http://code.haskell.org/haxr/examples/PersonTH.hs <tt>examples/PersonTH.hs</tt>]
 
does the same using the <code>Network.XmlRpc.THDeriveXmlRpcType</code>
 
does the same using the <code>Network.XmlRpc.THDeriveXmlRpcType</code>
 
module.
 
module.
Line 71: Line 73:
 
[http://code.haskell.org/haxr/examples/make-stubs.hs <tt>examples/make-stubs.hs</tt>] for an example of how to use introspection in a client.
 
[http://code.haskell.org/haxr/examples/make-stubs.hs <tt>examples/make-stubs.hs</tt>] for an example of how to use introspection in a client.
 
</p>
 
</p>
 
<h4>More examples</h4>
 
 
<p>More example are available in the [http://code.haskell.org/haxr/examples/ <tt>examples/</tt>] folder in the darcs repository.</p>
 
  
 
<h3>API reference</h3>
 
<h3>API reference</h3>
Line 95: Line 93:
  
 
<p>
 
<p>
You can get the latest versions of the [http://hackage.haskell.org/package/haxr <tt>haxr</tt>] and [http://hackage.haskell.org/package/haxr-th <tt>haxr-th</tt>] packagesfrom [http://hackage.haskell.org/ Hackage].
+
You can get the latest versions of the [http://hackage.haskell.org/package/haxr <tt>haxr</tt>] from [http://hackage.haskell.org/ Hackage].
 +
</p>
  
 +
<p>
 +
There used to be a separate <tt>haxr-th</tt>, now everything is available in <tt>haxr</tt>.
 
</p>
 
</p>
  
Line 114: Line 115:
  
 
<p>To report bugs, request features, submit patches, or ask for help, email
 
<p>To report bugs, request features, submit patches, or ask for help, email
[mailto:gracjanpolak@gmail.com Gracjan Polak].</p>
+
[mailto:byorgey@gmail.com Brent Yorgey].</p>
  
 
<p>Some known problems are listed in the  
 
<p>Some known problems are listed in the  
Line 132: Line 133:
 
Copyright 2003-2007 [mailto:bjorn@bringert.net Bj&ouml;rn Bringert].
 
Copyright 2003-2007 [mailto:bjorn@bringert.net Bj&ouml;rn Bringert].
 
Copyright 2009-2010 [mailto:gracjanpolak@gmail.com Gracjan Polak].
 
Copyright 2009-2010 [mailto:gracjanpolak@gmail.com Gracjan Polak].
 +
Copyright 2012 [mailto:byorgey@gmail.com Brent Yorgey].
 
</p>
 
</p>

Latest revision as of 13:56, 7 July 2012

Contents

1 HaXR — the Haskell XML-RPC library

HaXR is a library for writing XML-RPC client and server applications in Haskell.

Christopher Milton came up with the HaXR name, thanks!

1.1 Documentation

1.1.1 Examples


Example are available in the examples/ folder in the darcs repository. Here we talk about a couple of them.


1.1.1.1 Server

This is a simple CGI-based server with only one method that takes two integers and returns their sum.

import Network.XmlRpc.Server
 
add :: Int -> Int -> IO Int
add x y = return (x + y)
 
main = cgiXmlRpcServer [("examples.add", fun add)]

Note: the argument to fun can be a function that takes any number of arguments.

1.1.1.2 Client

This is a client that calls the method implemented by the server above and prints the result.

import Network.XmlRpc.Client
 
server = "http://localhost/~bjorn/cgi-bin/simple_server"
 
add :: String -> Int -> Int -> IO Int
add url = remote url "examples.add"
 
main = do
       let x = 4
	   y = 7
       z <- add server x y
       putStrLn (show x ++ " + " ++ show y ++ " = " ++ show z)

Note: the function returned by remote can be a function that takes any number of arguments.

1.1.1.3 Heterogeneous structs

Have a look at examples/Person.hs for an example of how to use heterogeneous structs. examples/PersonTH.hs does the same using the Network.XmlRpc.THDeriveXmlRpcType module.

1.1.1.4 XML-RPC introspection

This library supports XML-RPC introspection, both in the client and server. See examples/make-stubs.hs for an example of how to use introspection in a client.

1.1.2 API reference

Use the online copy of the API documentation.

1.1.3 Report

I have written a report (ps, pdf) on the design and implementation of Haskell XML-RPC. The report was written in January 2004, and is slowly getting out of date.

1.2 Download

1.2.1 Hackage

You can get the latest versions of the haxr from Hackage.

There used to be a separate haxr-th, now everything is available in haxr.


1.2.2 Darcs repository

Use darcs to get the source from the repo at http://code.haskell.org/haxr/:

$ darcs get http://code.haskell.org/haxr/


1.3 Reporting bugs, requesting features

To report bugs, request features, submit patches, or ask for help, email Brent Yorgey.

Some known problems are listed in the TODO file in the source distribution. If you need any of those fixed, let me know.

1.4 License

HaXR is distributed under a BSD-style license.

<div class="bar" />

Copyright 2003-2007 Björn Bringert. Copyright 2009-2010 Gracjan Polak. Copyright 2012 Brent Yorgey.