Chapter 5. Network I/O and Web Services
More and more these days, it seems like every system we build has to talk to something, somewhere. We’d hardly be doing anything if we didn’t actually talk with some other computers over some kind of network.
This chapter covers all of the normal remote communication modes you would expect—HTTP, TCP, UDP, and the like—as well as some relative newcomers like message-oriented architectures.
5.1. Making HTTP Requests
You want to make a simple HTTP GET or POST request.
slurp to make simple HTTP GET requests:
;; -> "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title> ...
clj-http library to make GET, POST, and other requests with
specific parameters or headers, to handle redirects and other special
circumstances, or to get specific details about the response.
To follow along, add
[clj-http "0.7.7"] to your project’s
dependencies, or use
lein-try to start a REPL:
$ lein try clj-http
clj-http.client/get to make GET requests:
;; -> 200
;; -> "nginx"
;; -> ("session-id" "session-id-time" "x-wl-uid" "skin")
Parameters can be included in both GET and POST requests. Use
clj-http.client/post to make POST requests: