Skip to content

Commit aac088e

Browse files
committed
0.9.3 Docs.
1 parent 0e67d71 commit aac088e

File tree

105 files changed

+19360
-2219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+19360
-2219
lines changed
File renamed without changes.
File renamed without changes.

_images/ftp_uri.png

25 KB
Loading

_images/ftp_uri1.png

25 KB
Loading

_images/http_uri.png

20.2 KB
Loading

_images/http_uri1.png

20.2 KB
Loading

_images/mailto_uri.png

9.98 KB
Loading

_images/mailto_uri1.png

9.98 KB
Loading

_sources/atom_reader.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
.. _atom_reader:
2+
3+
*************
4+
Atom reader
5+
*************
6+
7+
The next examples show some simple, more practical applications using
8+
the HTTP client. The first one reads a simple Atom feed and prints
9+
the titles of each entry to the console.
10+
11+
The code
12+
========
13+
14+
.. code-block:: c++
15+
16+
#include "atom.hpp"
17+
#include <boost/network/protocol/http/client.hpp>
18+
#include <boost/foreach.hpp>
19+
#include <iostream>
20+
21+
int main(int argc, char * argv[]) {
22+
using namespace boost::network;
23+
24+
if (argc != 2) {
25+
std::cout << "Usage: " << argv[0] << " <url>" << std::endl;
26+
return 1;
27+
}
28+
29+
try {
30+
http::client client;
31+
http::client::request request(argv[1]);
32+
request << header("Connection", "close");
33+
http::client::response response = client.get(request);
34+
atom::feed feed(response);
35+
36+
std::cout << "Feed: " << feed.title()
37+
<< " (" << feed.subtitle() << ")" << std::endl;
38+
BOOST_FOREACH(const atom::entry &entry, feed) {
39+
std::cout << entry.title()
40+
<< " (" << entry.published() << ")" << std::endl;
41+
}
42+
}
43+
catch (std::exception &e) {
44+
std::cerr << e.what() << std::endl;
45+
}
46+
47+
return 0;
48+
}
49+
50+
Building and running ``atom_reader``
51+
====================================
52+
53+
.. code-block:: bash
54+
55+
$ cd ~/cpp-netlib-build
56+
$ make atom_reader
57+
58+
And to run the example from the command line to access the feed that
59+
lists of all the commits on cpp-netlib's master repository:
60+
61+
.. code-block:: bash
62+
63+
$ ./example/atom_reader https://github.com/cpp-netlib/cpp-netlib/commits/master.atom
64+
65+
Diving into the code
66+
====================
67+
68+
Most of this will now be familiar. The response is passed to the
69+
constructor to the ``atom::feed`` class, which parses the resultant
70+
XML. To keep this example as simple as possible, `rapidxml`_, a
71+
header-only XML parser library, was used to parse the response.
72+
73+
.. _`rapidxml`: http://rapidxml.sourceforge.net/
74+
75+
A similar example using RSS feeds exists in
76+
``libs/network/example/rss``.
File renamed without changes.

0 commit comments

Comments
 (0)