Giter VIP home page Giter VIP logo

webmachine_ruby_shortener's Introduction

This is a super simple example app built with webmachine-ruby (the Ruby port of the Erlang webmachine library).

The app is a simple URL shortener.

Create Shortened URLs

POST to the root path to create a shortened link. Set the Content-Type to application/json and pass in JSON data as the request body with a "url" field. In our example, we're creating a shortened link to http://www.example.com

curl -v http://localhost:8080 -d '{"url":"http://www.example.com"}' -H "Content-Type: application/json"
* About to connect() to localhost port 8080 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8080
> Accept: */*
> Content-Type: application/json
> Content-Length: 32
> 
< HTTP/1.1 201 Created 
< Content-Type: application/json
< Location: http://localhost:8080/yr9hm
< X-Webmachine-Trace-Id: 70195680386660
< Content-Length: 0
< Server: Webmachine-Ruby/1.0.0 Rack/1.1
< Date: Sat, 21 Jul 2012 14:20:19 GMT
< Connection: Keep-Alive
< 
* Connection #0 to host localhost left intact
* Closing connection #0

The generated short link is contained in the Location field: http://localhost:8080/yr9hm in this case.

Follow Shortened URLS

GET the location given when creating a request.

curl -v http://localhost:8080/yr9hm
* About to connect() to localhost port 8080 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /yr9hm HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently 
< Content-Type: application/json
< Location: http://www.example.com
< X-Webmachine-Trace-Id: 70195680433860
< Content-Length: 0
< Server: Webmachine-Ruby/1.0.0 Rack/1.1
< Date: Sat, 21 Jul 2012 14:24:17 GMT
< Connection: Keep-Alive
< 
* Connection #0 to host localhost left intact
* Closing connection #0

This serves up a redirect to the original URL we created a shortend URL for

webmachine_ruby_shortener's People

Contributors

madlep avatar dependabot[bot] avatar

Stargazers

 avatar Jeremy Hinegardner avatar Ivan Storck avatar Anatoly Chernov avatar Yury Batenko avatar Alex Babkin avatar  avatar

Watchers

 avatar Paulo A Pereira avatar James Cloos avatar Anatoly Chernov avatar  avatar

Forkers

chinnurtb calopez

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.