Giter Site home page Giter Site logo

linkr's Introduction

Linkr

URL shortener implemented using Scala, Akka HTTP, Cassandra, and Phantom.

This example project should give you an idea how to use Cassandra and Akka HTTP together. It is not intended to be used in production but rather as a learning resource.

Getting Started

Make sure you have Scala, git, and sbt installed.

Clone the repository and go to the project directory:

git clone https://github.com/vaiski/linkr.git
cd linkr

Run the service using sbt:

sbt run

The service listens by default port 5000.

Usage and Functionality

Create a Short Link

Create a short link by making a POST request to /links with your favourite command line tool (personally, I prefer the awesome HTTPie, but the examples use cURL for its ubiquity):

curl -is -H "Content-Type: application/json" \
         -X POST http://localhost:5000/links \
         -d '{"id": "myblog", "url": "https://vaiski.com"}'

The server should respond with the created shortlink resource:

HTTP/1.1 200 OK
Content-Length: 77
Content-Type: application/json
Date: Sun, 07 May 2017 20:04:14 GMT
Server: akka-http/10.0.6

{
    "createdAt": "2017-05-07T19:59:44Z",
    "id": "myblog",
    "url": "https://vaiski.com"
}

Access a Link

Navigate with your web browser to http://localhost:5000/myblog or make a GET request using command line:

curl -is http://localhost:5000/myblog

The server should respond with a redirection to the target URL:

HTTP/1.1 301 Moved Permanently
Content-Length: 0
Content-Type: application/json
Date: Sun, 07 May 2017 20:07:20 GMT
Location: https://vaiski.com
Server: akka-http/10.0.6

Show Link Information

To get the link details, make a GET request to the /links/<link_id> URL:

curl -is http://localhost:5000/links/myblog

The service should return the details of the shortlink resource:

HTTP/1.1 200 OK
Content-Length: 77
Content-Type: application/json
Date: Sun, 07 May 2017 20:04:36 GMT
Server: akka-http/10.0.6

{
    "createdAt": "2017-05-07T19:59:44Z",
    "id": "myblog",
    "url": "https://vaiski.com"
}

Acknowledgments

This project draws from the great examples and conventions presented by Daniela Sfregola in her blog post How to build a REST API with Akka Http and the related GitHub repository.

linkr's People

Contributors

vaiski 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.