Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/kuthumipepple/stocks-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/kuthumipepple/stocks-api

  • v0.0.0-20230810101230-2f1af56603c9
  • Source
  • Go
  • Socket score

Version published
Created
Source

Stocks API

License: MIT

This API provides endpoints for managing stocks

Getting started

To run this application as-is:

  1. Clone the repository and navigate to the project directory
  2. Run go mod download command to download all the dependencies.
  3. Create a PostgreSQL database. Create a table named stocks. The columns should align with the Stock model in the models package with the stockid column set as SERIAL PRIMARY KEY
  4. Edit the .env file to use your database details.
  5. Run go run main.go command to start the application

Endpoints

EndpointMethodDescription
/api/stocksPOSTInsert a new stock
/api/stocksGETGet all stocks
/api/stocks/{id}GETGet stock by ID
/api/stocks/{id}PUTUpdate an existing stock
/api/stocks/{id}DELETEDelete a stock

Consuming the API

Use any http client program to make HTTP requests to the running server. Here are some Request examples:

Insert a new Stock

Request

POST /api/stocks

{
    "symbol": "AB",
    "price": 19,
    "company": "Company1"
}
Response

201 Created

{
    "id": 1,
    "message": "stock created successfully"
}

Get all Stocks

Request

GET /api/stocks

Response

200 OK

[
    {
        "stockid": 1,
        "symbol": "AB",
        "price": 19,
        "company": "Company1"
    },
    {
        "stockid": 2,
        "symbol": "CDE",
        "price": 152,
        "company": "Company2"
    },
    ...
    ...
]

Get Stock by ID

Request

GET /api/stocks/1

Response

200 OK

{
    "stockid": 1,
    "symbol": "AB",
    "price": 19,
    "company": "Company1"
}

Update an existing Stock

Request

PUT /api/stocks/1

{
    "price": 25
}
Response

200 OK

{
    "id": 1,
    "message": "stock updated successfully. Total records affected: 1"
}

Delete a Stock

Request

DELETE /api/stocks/2

Response

200 OK

{
    "id": 2,
    "message": "Stock deleted. Total records affected: 1"
}

FAQs

Package last updated on 10 Aug 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc