Giter Site home page Giter Site logo

michael-ortiz / url-shortner-api Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 37 KB

A Lambda API backend hosted in AWS using Terraform to generate short URL's from long ones. Easily connect this backend to any front end app. Happy coding! ๐Ÿ˜ƒ

Home Page: https://cutmyurl.com

HCL 44.97% JavaScript 55.03%
aws serverless terraform url-shortener api shortener lambda dynamodb url-shortener-api

url-shortner-api's Introduction

url-shortner-api

AWS Hosted Project

This project contains the necessary infrastructure as code and lambda code to host a URL shortener API. Convert any long URL's to a short one. Easily connect this API to your front end application.

AWS Services Used:

  • AWS Lambda: For the backend API.
  • AWS DynamoDB: For storing link references.

โš™๏ธ Installation

To deploy the application you must have terraform cli and aws cli installed.

You must have a aws profile configured for terraform to use it and deploy it into your AWS account:

aws configure --profile <YOUR_PROFILE_NAME>

To begin, open the provider.tf file and under the aws provider change the profile used. Put your own profile name in <YOUR_AWS_CONFIGURE_PROFILE>. Then change the <YOUR_AWS_REGION> to us-east-1.

provider "aws" {
  region = "us-east-1"
  profile = "profile_name"
}

Next, go to vars.tf and change in locals the following values: domain_name and domain_protocol.

๐Ÿš€ Deployment

Execute the following commands to deploy the infrastructure and lambdas:

npm install --prefix ./functions/get-short-url
terraform init
terraform apply

Once deployed, you should see in the outputs the URL's pointing to your lambdas.

๐Ÿ”— API Usage

The API contains 3 different lambdas. Below we explain how to use each:

  • get_short_url: Generates the shortValue from a long url and stores it in a DynamoDB table.
  • get_original_url: Fetches the original URL by passing a shortValue generated by the first API call.
  • get_url_stats: Fetches details about a URL without increasing the viewsCount property.

Get Short URL

Method: POST

URL Example: (See Terraform output for get_short_url_function_url for actual URL)

https://<ID>.lambda-url.us-east-1.on.aws/

Request Body:

{
    "url": "https://google.com",
    "alias": "custom-alias"
}

Response Body:

{
    "lastViewedDate": "2023-02-06T00:15:05.319Z",
    "createdDate": "2023-02-06T00:15:05.319Z",
    "shortUrl": "https://<YOUR_DOMIAN_NAME>/oaIL23dz",
    "viewsCount": 0,
    "shortValue": "oaIL23dz",
    "originalUrl": "https://google.com"
}

Properties


url

Description: A long url. Support https, http and non protocol URL's.

Required: Yes

Type: string


alias

Description: A custom alias (name) for the URL. If this is used, a random ID will not be returned and instead a custom alias will be used.

Required: No

Type: string


Get Original URL

Method: GET

URL Example: (See Terraform output for get_original_url_function_url for actual URL)

https://<ID>.lambda-url.us-east-1.on.aws

Request Query:

https://<ID>.lambda-url.us-east-1.on.aws?shortValue=<SHORT_VALUE>

Response Body:

{
    "viewsCounter": "2",
    "lastViewedDate": "2023-02-06T00:47:44.471Z",
    "createdDate": "2023-02-06T00:44:01.242Z",
    "shortUrl": "https://<YOUR_DOMAIN_NAME>/lgatGICp",
    "shortValue": "lgatGICp",
    "originalUrl": "https://google.com"
}

Query Parameters


shortValue

Description: A unique ID that will be used as the URL path. This value is returned when first creating a shortUrl.

Required: Yes

Type: string


Get URL Statistics

Method: GET

URL Example: (See Terraform output for get_url_stats_function_url for actual URL)

https://<ID>.lambda-url.us-east-1.on.aws

Request Query:

https://<ID>.lambda-url.us-east-1.on.aws?shortValue=<SHORT_VALUE>

Response Body:

{
    "viewsCounter": "2",
    "lastViewedDate": "2023-02-06T00:47:44.471Z",
    "createdDate": "2023-02-06T00:44:01.242Z",
    "shortUrl": "https://<YOUR_DOMAIN_NAME>/lgatGICp",
    "shortValue": "lgatGICp",
    "originalUrl": "https://google.com"
}

Query Parameters


shortValue

Description: A unique ID that will be used as the URL path. This value is returned when first creating a shortUrl.

Required: Yes

Type: string


url-shortner-api's People

Contributors

michael-ortiz avatar

Stargazers

 avatar  avatar  avatar

Watchers

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