Coder Social home page Coder Social logo

eillanrt / iksi Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 246 KB

Demonstrates simple CRUD operations and performs common HTTP requests through a basic URL shrinker web server

License: MIT License

JavaScript 35.00% HTML 41.29% EJS 6.84% CSS 16.88%
basic-server express javascript mongodb nodejs url-shortener css html

iksi's Introduction

iksi

A simple url-shrinker web server

Thanks for Bard for writing some CSS for me!


RUN

  • Go to https://mongodb.com. Set up a database and get URI. Choose nodeJS as the driver
  • Creata a .env file and add MONGODB_URI key with a corresponding value of the URI obtained from mongoDB
  • install necessary dependecies npm install
  • run the server npx nodemon server.js
  • Open http://127.0.0.1:3000 on browser

GET /:short_url

Will redirect to the corresponding original URL if it is a valid short url. Otherwise it will respond with 404

POST /shorten

The following code demonstrates how to send POST request to the server

async function getShortURL(longURL) {
  const res = await fetch('/shorten', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ original_url: longURL }),
  })

  const data = await res.json()
  /*
    data
    {
      _id: mongoDB ID
      original_url: <long_url>,
      short_url: a short string that serves as the path to that original url,
      number_of_visits: how many times the short_url has been clicked/opened
    }
  */

  return data.short_url
}

getShortURL('https://www.youtube.com/watch?v=EFwa5Owp0-k').then(shortURL => {
    console.log(shortURL)
})

Then append that short id string in to the origin

http://127.0.0.1:3000/<short-id-string>

DELETE /delete

Deletes a specified URL Data

Screenshots

Screenshot of form

Screenshot of form

iksi's People

Contributors

eillanrt avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 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.