User Tools

Site Tools


cs326:lab4

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs326:lab4 [2021/09/29 20:33]
scarl [Part II. Exploring the HTTPoison library]
cs326:lab4 [2021/10/04 15:46]
scarl
Line 105: Line 105:
 Let's load up and explore the ''​HTTPoison''​ library. This library provides a set of modules and functions to query web resources programmatically. Edit **mix.exs**,​ by adding the following map to the list in ''​deps'':​ Let's load up and explore the ''​HTTPoison''​ library. This library provides a set of modules and functions to query web resources programmatically. Edit **mix.exs**,​ by adding the following map to the list in ''​deps'':​
  
- ''​{:​httpoison,​ "~> 1.0"}''​+<​code>​{:​httpoison,​ "~> 1.0"}</​code>​
  
 Save the file and run  Save the file and run 
Line 137: Line 137:
 <​code>​exports HTTPoison</​code>​ <​code>​exports HTTPoison</​code>​
  
-Quite a list! Use help to find out more about the ''​get!''​ function:+Quite a list! Veterans of CSci 284 or 428 might recognize some of these functions as names of HTTP methods like GET and PUT. Use help to find out more about the ''​get!''​ function:
  
 <​code>​h HTTPoison.get!</​code>​ <​code>​h HTTPoison.get!</​code>​
Line 145: Line 145:
 <​code>​HTTPoison.get! "​http://​scarl.sewanee.edu"</​code>​ <​code>​HTTPoison.get! "​http://​scarl.sewanee.edu"</​code>​
  
-This should return a struct ''​%HTTPoison.Response''​ with four fields. Find and **record** the field names (think maps, again) and the type of data in them. +This should return a struct ''​%HTTPoison.Response''​ with four fields. Find and **record** the field names (think maps, again) and the //type// of data in them. You might recognize the contents of the first field as HTML.
  
 Let's save this response in a variable: Let's save this response in a variable:
Line 163: Line 163:
 Ask for a page on my classes website that probably doesn'​t exist. **Record** the webpage requested and the ''​status_code''​ you get. Ask for a page on my classes website that probably doesn'​t exist. **Record** the webpage requested and the ''​status_code''​ you get.
  
-Finally, try these. For the first two, **record** the ''​headers''​ list. For the next two, **record** the response. For the last one, **record** the __first five__ maps in the ''​headers'' ​list.+Finally, try these. For the first two, **record** the ''​headers''​ list. For the rest, **record** ​the first element of the response ​tuple and the ''​status_code'' ​if it works.
  
 <​code>​ <​code>​
Line 170: Line 170:
 HTTPoison.get "​http://​127.0.0.1"​ HTTPoison.get "​http://​127.0.0.1"​
 HTTPoison.get! "​http://​127.0.0.1"​ HTTPoison.get! "​http://​127.0.0.1"​
 +HTTPoison.get "​http://​api.github.com/​repos/​elixir-lang/​elixir/​issues"​
 HTTPoison.get "​https://​api.github.com/​repos/​elixir-lang/​elixir/​issues"​ HTTPoison.get "​https://​api.github.com/​repos/​elixir-lang/​elixir/​issues"​
 </​code>​ </​code>​
 All done! Exit ''​iex''​. All done! Exit ''​iex''​.
cs326/lab4.txt ยท Last modified: 2021/10/04 15:46 by scarl