Socket
Book a DemoInstallSign in
Socket

github.com/repoleved08/stock-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/repoleved08/stock-api

v0.0.0-20241024155853-ee0404ef9067
Source
Go
Version published
Created
Source

Stock Management API

This is a simple Golang API that performs CRUD (Create, Read, Update, Delete) operations on stock data. The API uses the gorilla/mux router and interacts with stock details, including id, name, price, and company.

Features

  • Add stock information
  • Retrieve stock information
  • Update stock information
  • Delete stock information

API Endpoints

Base URL

http://localhost:8000/api/stock

Endpoints

  • Create Stock (POST)
    Adds a new stock entry.
    URL: /api/stock
    Method: POST
    Request Body:

    {
        "name": "string",
        "price": float,
        "company": "string"
    }
    
  • Get All Stock (GET)
    Retrieves all stock entries.
    URL: /api/stock
    Method: GET

  • Get Stock by ID (GET)
    Retrieves a specific stock entry by id.
    URL: /api/stock/{id}
    Method: GET

  • Update Stock (PUT)
    Updates stock information for a specific id.
    URL: /api/stock/{id}
    Method: PUT
    Request Body:

    {
        "name": "string",
        "price": float,
        "company": "string"
    }
    
  • Delete Stock (DELETE)
    Deletes a specific stock entry by id.
    URL: /api/stock/{id}
    Method: DELETE

Installation

  • Clone the repository

    git clone https://github.com/your-username/stock-api.git
    cd stock-api
    
  • Install dependencies Ensure you have Go installed. Run the following command to install the necessary packages:

    go mod tidy
    
  • Run the API

    go run main.go
    
  • Access the API The API will be running at http://localhost:8000.

Project Structure

.
├── main.go         # Entry point of the application
├── routes.go       # API routing definitions
├── handlers.go     # Request handlers for CRUD operations
└── models.go       # Stock struct and any data models

Example Request for Creating Stock

curl -X POST http://localhost:8000/api/stock \
  -H "Content-Type: application/json" \
  -d '{
        "name": "Apple Inc.",
        "price": 145.30,
        "company": "Apple"
      }'

Technologies Used

  • Golang — Programming language used to build the API.
  • Gorilla Mux — HTTP router and URL matcher for Golang.

Future Improvements

  • Add authentication (e.g., JWT) for securing the API.
  • Implement pagination and filtering for the stock listings.
  • Add database support (e.g., PostgreSQL, MySQL).

FAQs

Package last updated on 24 Oct 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.