Giter Site home page Giter Site logo

tiny_url_api's Introduction

Tiny Url Api

A Symfony project created on September 28, 2016, 4:32 pm. An api transforming long urls to cute tiny ones

Getting Set Up:

  • Requires PHP 5.6 or higher
  • Composer required for package installation

Clone and install packages:

$ git clone https://github.com/jlappano/tiny_url_api.git
$ cd tiny_url_api/
$ composer install

Set up the database:

$ php bin/console doctrine:database:create
$ php bin/console doctrine:schema:update --force
$ php bin/console doctrine:fixtures:load

Run the tests:

$ vendor/bin/phpunit tests/ApiBundle

Run the server:

$ php bin/console server:run

Using the API


Route: api/url/list

Description: Retrieves a list of all existing shortened URLs, including time since creation and target URLs (each with number of redirects)

Verb: GET

Required Parameters: NONE!

Sample Response:

Response Code 200

"[{
    "tinyUrl":"tiny.cj",
    "timeStamp":"8 months, 29 days, and 19 hours and 43 minutes ago",
    "desktopRedirects":0,
    "tabletRedirects":0,
    "mobileRedirects":0
},
{
    "tinyUrl":"tiny.9m",
    "timeStamp":"8 months, 28 days, and 19 hours and 43 minutes ago",
    "desktopRedirects":0,
    "tabletRedirects":0,
    "mobileRedirects":0
}]"

Route: api/url/create

Description: Submit any URL and get a standardized, shortened URL back.

Verb: POST

Required Parameters:

"{
    "url":"http:\/\/my_very_long_testing_url_that_goes_on_forever_and_ever177798827272727"
}"

Sample Response:

"{
    "tiny url":"tiny.38"
 }"

Route: api/url/update

Description: Configure a shortened URL to redirect to different targets based on the device type (mobile, tablet, desktop) of the user navigating to the shortened URL.

Verb: PUT

Required Parameters:

"{
    "tiny_url":"tiny.38"
}"

Optional Parameters:

"{
    "tablet_target":"http:\/\/tablet/testTarget",
    "mobile_target":"http:\/\/mobile/testTarget",
    "desktop_target":"http:\/\/desktop/testTarget"
}"

Sample Response: 200 OK


Route: api/url/redirect

Description: Navigate to a shortened URL, redirecting to the appropriate target URL based on the device type (mobile, tablet, desktop) of the user.

Verb: GET

Required Parameters:

"{
    "tiny_url":"tiny.cj"
}"

Sample Response: 302 Redirect

Redirecting From the Broswer

With the local server running, enter existing Tiny Url into the browser window. The url below will redirect to 'http://boingboing.net/' on desktops, 'https://news.ycombinator.com/' on tablets, and 'https://www.google.com/' on mobile devices:

http://localhost:8000/tiny.3k

tiny_url_api's People

Contributors

jlappano avatar

Watchers

 avatar

tiny_url_api's Issues

Small issues during installation

I pulled down and installed the application, but ran into a few small issues. None of them prevented the app from loading but I wanted to log them just in case:

  • During the ScriptHandler::buildParameters(), it outputs the database path with a template variable instead of the path: "('%kernel.root_dir%/data.db3'):"
  • Symfony throws a ContextErrorException, citing "It is not safe to rely on the system's timezone settings." I fixed this by adding a date.timezone = "UTC" in my php.ini, but I think there's a way to detect this. I only raise this issue because I think it prevented the bin/console and server commands from properly running.
  • The app doesn't provide any validation that the URL is in fact a URL. It will encode any string passed in via POST with the name 'url' to the create endpoint. This might not be a bug, because if I encode the string "asdasd" it re-routes to "localhost:8000/asdasd".

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.