This week I went into the 'http' portion of the launch academy curriculum and finished about half a week's worth of material (essentially 5 lessons). So I got a chance to review the fundamentals of the http request/response cycle, generate dynamic views with user generated content and receiving data as post requests from users. yep. I re-covered URL basics. reviewed 'scheme' which helps determine the protocol used to make the request. reviewed 'hostname' used to identify the host, or server of the information being retreived- path, etc. Reviewed example query string parameters and read more about query strings in this article, basically a lot of stuff we covered in our internet tutorial but good to review. Read about URL fragments. I learned how to use the URI classwhich is how ruby works with URLs. reviewed the CRUD actions and read this REST api quick tips article. reviewed status codes, and then made some GET requests using curl and localhost...
I had all the examples but actually exited out of terminal by accident.
Also created a new message with POST ...using curl...
and updated a message with PATCH using curl
Finally, deleted a message using the DELETE request.
I also played around with some code that would interact with different web servers:
weather.rb
require "net/http"
require "active_support/core_ext/hash"
require "pp"
weather_url = "https://forecast.weather.gov/MapClick.php?lat=42.35&lon=-71.06&FcstType=dwml"
uri = URI.parse(weather_url) # convert the URL string to a URI object
response = Net::HTTP.get_response(uri) # issue a HTTP GET request
body = Hash.from_xml(response.body) # convert XML to a more familiar data type
pp body # "pretty-print" the hash
... (and this gave me the weather forecast)
Finally I made a to-do list (See pictures) and changed the css to make it look plain, than fancy.
See the following files:
server.rb
require "sinatra"
set :bind, '0.0.0.0'
set :public_folder, File.join(File.dirname(__FILE__), "public")
get "/hello" do
"<p>hello! the current time is #{Time.now}</p>"
end
get "/tasks" do
'''
<!DOCTYPE html>
<html>
<head>
<title>Basic HTML Page</title>
<link rel="stylesheet" href="home.css">
</head>
<body>
<h1>TODO list</h1>
<ul>
<li>pay bills</li>
<li>go dancing</li>
<li>buy milk</li>
<li>learn Ruby</li>
</ul>
</body>
</html>
'''
end
home.html
<!DOCTYPE html>
<html>
<head>
<title>Basic HTML Page</title>
<link rel="stylesheet" href="home.css">
</head>
<body>
<h1>this is a test mothafuckka...DUDE IS MY FONT GOING TO CHANGE LIKE THIS</h1>
<ul>
<li>testing!</li>
<li>one</li>
<li>LESLIE YOU CAn't</li>
</ul>
</body>
</html>
home.css
body {
background-color: black;
color: #00ff00;
font-family: monospace;
font-size: 1.5em;
}
ul {
width: 300px;
border: 1px solid #00ff00;
}
li {
padding: 5px;
}
last modified | size | ||
Screen_Shot_2018-11-20_at_7.01.03_PM.png | Wed Dec 04 2024 07:00 pm | 86K | |
Screen_Shot_2018-11-20_at_7.01.10_PM.png | Wed Dec 04 2024 07:00 pm | 32K | |
Screen_Shot_2018-11-20_at_7.44.34_PM.png | Wed Dec 04 2024 07:00 pm | 153K |