🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

github.com/pol-cova/go-url-shortener-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/pol-cova/go-url-shortener-api

v0.0.0-20240715163444-eb2541ae9976
Source
Go
Version published
Created
Source

Go URL Shortener API Documentation

Overview

The Go URL Shortener API allows users to create shortened URLs for easy sharing and management. It includes endpoints for user authentication, URL shortening, and user profile management, using JWT for authentication.

Base URL

http://localhost:8080

Authentication

Include the JWT token in the Authorization header for protected endpoints. Authorization: <your-token>

Endpoints

Auth Routes

Signup

  • Endpoint: /auth/signup
  • Method: POST
  • Request Body:
    {
      "email": "string",
      "password": "string"
    }
    

Login

  • Endpoint: /auth/login
  • Method: POST
  • Request Body:
    {
      "email": "string",
      "password": "string"
    }
    
  • Response:
    {
      "token": "your-jwt-token"
    }
    

Logout

  • Endpoint: /auth/logout
  • Method: GET

URL Routes

Shorten URL

  • Endpoint: /short
  • Method: POST
  • Request Body:
    {
      "url": "string"
    }
    
  • Response:
    {
      "shortened_url": "http://localhost:8080/:key"
    }
    

Redirect URL

  • Endpoint: /:key
  • Method: GET

User Routes

These routes require authentication.

Shorten URL (Authenticated User)

  • Endpoint: /user/short
  • Method: POST
  • Request Body:
    {
      "url": "string"
    }
    

Home

  • Endpoint: /user/home
  • Method: GET
  • Response:
    [
      {
        "id": 1,
        "url": "https://example.com",
        "key": "abc123",
        "created_at": "2023-01-01T00:00:00Z",
        "clicks": 100,
        "user_id": 1
      },
      {
        "id": 2,
        "url": "https://anotherexample.com",
        "key": "xyz789",
        "created_at": "2023-01-02T00:00:00Z",
        "clicks": 50,
        "user_id": 1
      }
    ]
    

Profile

  • Endpoint: /user/me
  • Method: GET
  • Response:
    {
      "email": "string"
    }
    

Delete Account

  • Endpoint: /user/delete
  • Method: DELETE

Running the Project

  • Clone the repository:
    git clone https://github.com/pol-cova/go-url-shortener-api.git
    
  • Navigate to the project directory:
    cd <go-url-shortener-api>
    
  • Run the project:
    go run .
    

The server will start on port 8080.

FAQs

Package last updated on 15 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts