Coder Social home page Coder Social logo

fdbeirao / url Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elm/url

0.0 1.0 0.0 81 KB

Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)

License: BSD 3-Clause "New" or "Revised" License

JavaScript 0.78% Elm 99.22%

url's Introduction

Work with URLs

This library has two primary modules:

  • Url to build URLs for HTTP requests
  • Url.Parser to parse URLs for “routing” in single-page apps (SPAs)

Check out those modules for specific usage examples!


What is a URL?

A URL is defined by Tim Berners-Lee in this document. It is worth reading, but I will try to share some highlights. He shares an example like this:

  https://example.com:8042/over/there?name=ferret#nose
  \___/   \______________/\_________/ \_________/ \__/
    |            |            |            |        |
  scheme     authority       path        query   fragment

And here are some facts that I found surprising:

  • ASCII only — Behavior with other encodings is undefined in the spec. So a browser may handle a non-ASCII character one way, while this library handles it another. No one is wrong. It is just unspecified. I would stick to ASCII to be safe.

  • Escaping — The spec uses the term percent-encoded to reduce confusion with other escape mechanisms. The format is %XX allowing two hex digits. According to this table of ASCII characters, you could encode ? as %3F and = as %3D. There are many subtleties though, so I recommend reading this for more information!


Note: The difference between a URI and a URL is kind of subtle. This post explains the difference nicely. I decided to call this library elm-lang/url because it is primarily concerned with HTTP which does need actual locations.


Related Work

The API in Url.Parser is quite distinctive. I first saw the general idea in Chris Done’s formatting library. Based on that, Noah and I outlined the API you see in Url.Parser. Noah then found Rudi Grinberg’s post about type safe routing in OCaml. It was exactly what we were going for. We had even used the names s and (</>) in our draft API! In the end, we ended up using the “final encoding” of the EDSL that had been left as an exercise for the reader. Very fun to work through!

url's People

Contributors

evancz avatar process-bot avatar viir avatar nataliecz avatar drzhbe avatar ulrikstrid avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.