*Quick note: This hasn't been updated to correspond for the lecture guide. If you have any questions about content here, please reach out to a TA.
Vocab
Let’s get ready for some vocab :D
- What is an HTTP Request?
- When we log onto Facebook’s messenger.com, our browser is the client. We send a request to GET all of the information from Facebook (’s server) so we can see it within our browser. This allows us to see the messages on our screen. Then when we send a message we are POSTing it (sending it to their server) so it can be stored somewhere. Then, the other person who we are messaging now GETs the messages in the conversation and sees the updated message in the server. This looks like a new message on our screen!
- In reality, facebook messenger is a bit more complicated than this, but in short, requests are how websites communicate with eachother. Usually our browser does the work of sending and receiving the requests, but we can do it too!
- The “GET” and “POST” are called requests. They are the methods that direct the interaction between a client and a server!
- If you would like to learn more about HTTP and Requests, here is a kind of long, but really really good read:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
(Peep the HTTP request methods on the left side of your screen on the dropdowns while you’re there)
Now what does this all look like in code?
Curl
Let’s find out! With a little help from a thing called cURL. The process will be very similar
-
Setup
- First, go to your command line. On Macs, press
command + space and type in “terminal” and hit enter. If you are on Mac, something like this should pop up:

-
Type in the command curl and hit enter. You should see:


-
If you don’t, and feel confident with installing command line tools on your machine, follow the steps here:
https://github.com/curl/curl. I would recommend adding curl to your path env variables! If not, you can use https://onlinecurl.com/ for now :) Otherwise, ask a TA or the Instructors!
-
Using Curl
- What is curl?
- Feel free to check out the docs for detailed information: https://curl.haxx.se/docs/httpscripting.html
- Remember that request stuff we were talking about earlier? cURL allows us to actually do all of this file and information transferring right from the command line!
- You should run
curl --help to see what types of commands are at your fingertips.
- Yeah, it’s pretty powerful. For now, let’s just worry about sending a request!
- Start by clicking this link: https://ethereal-ninja-1.glitch.me/
- By visiting this website, we are implicitly sending a GET request to the server that hosts it. We are GETting the data from it. But, alas, it seems like we weren’t supposed to visit the URL from our browser; we must visit it through the command line.
-
Let’s try a basic command:
- Enter this in your terminal:
curl <https://ethereal-ninja-1.glitch.me/>
- What happened? Congrats :)
- You just sent your first intentional request! But, how did it work?
- Curl has a bunch of cool shortcuts. Curl implicitly sends a GET to any url that you enter after it unless you specify a different method.
- Let’s try a more explicit way of achieving the same result:
- Enter in:
curl -X GET <https://ethereal-ninja-1.glitch.me/> in your terminal
- To send a request, the usual format is
curl -X [Request Method] [URL] (do not include the brackets)
- And that’s basically it. Let’s try a different kind of request now!
-
More complex requests
- When we want to send info to a server, we use a post request. We can accomplish this by replacing "GET" with "POST"! Try:
curl -X POST '<https://ethereal-ninja-1.glitch.me/'>
- It'll ask for a content parameter... what's that? The web would be pretty boring and tedious if the only thing we could do is send a request. It becomes more interesting when you can send data with the request as well!
-
Let's update our template for cURL requests:
curl -X [Request Method] [URL] -d [data string]
- The data string will be structured like this:
param1=this is param 1¶m2=this is param2
- Now try to send a post to that url from earlier but this time specifying a content parameter!
-
Now you should be ready to try this lab's mini-challenges!
- Here are the routes you should check out. Your goal: make some posts on the message forum and get your attendance link!
- Routes:
- ‘/classified’
- ‘/authenticate’
- ‘/newMessage’
- ‘/allMessages’
- ‘/updateMessage’
After you are done, enter your key in your
your.rails.world account under the attendance tab!
CONGRATS YOU’RE DONE!
You are free to go after if you would like. We are doing a run through of git that you can feel free to stay for!