Skip to content

Instantly share code, notes, and snippets.

@thejmazz
Last active March 8, 2016 08:01
Show Gist options
  • Save thejmazz/e8a64f040039dfdae3ed to your computer and use it in GitHub Desktop.
Save thejmazz/e8a64f040039dfdae3ed to your computer and use it in GitHub Desktop.

see URLs

What is a URL?

A Uniform Resource Locator is a subset of the Uiniform Resource Identifier (URI) family. In that, a URL is totally specific, contrary to a URI which can be "general", since a URI can be defined as "a string of characters used to identify a resource" Some example URLs are

  • http://www.rcsb.org/
  • http://www.ncbi.nlm.nih.gov/

Some example URIs are

  • http://www.uniprot.org/
  • ISBN 0-486-27557-4
  • GO:0006915

What is a Reqeust?

A Request is defined by a HTTP method, URL, Headers, and Body if the body is supported for that method (e.g. GET requests do not have a body).

Imagine a scenario, if you will. In the center of some megacity (where it is always raining btw), there is a big corporate headquarters. This corparation has full control over the timing of street lamps, hours of operation of various restaurants and othewise establishments of business, etc. We will call this corporate headquarters the MAINFRAME. You, an individual of this metropolis, are referred to as one of many CLIENTs. Communication between clients and the mainframe can only be conducted on various channels, which are GET and POST for simplicity. Let's say you forgot which hours of the day you are permitted to walk outside. So, you can send a GET request to /api/curfew/hours which returns 00:01-23:59. You identified that you simply wanted some existing data, the URL was used to determine which peice of data on the mainframe to send out, and a plain text response was sent back. Then you decide to petition for another second of outside time, so you write up a proposal. This proposal happens to be in JSON format and looks like

{
  "proposal": {
    "title": "Proposal for benefits of the outside",
    "content": "because reasons"
  }
}

To send a POST request, you need to know the URL, required Headers, and format of the body that is expected by the mainframe. Headers are just key:value pairs. The body is as above. So, using curl, one could POST over a peice of information, i.e. plain text, likely following a format of some sorts, so that the mainframe can receive it and process it.

curl -X POST http://mainframe/proposals -H "Content-Type:application/json" -d '{"foo": "bar"}'

This could be done with Postman with:

screen shot 2016-03-08 at 2 47 08 am

screen shot 2016-03-08 at 2 46 24 am

HTTP Verbs

When discussing plans with another individual, and especially if communication takes a long time, you will want to define some simple verbs so that the exchange of information, items, etc. is defined clearly, and you will not wind up in circles of exchange. The four most common HTTP verbs are GET, POST, PUT, and DELETE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment