Welcome to the documentation for the StocksAPI, a simple RESTful API for managing stock information. This API is built using the Go programming language and the Gorilla Mux router.
Get information about a specific stock by providing its ID.
- Endpoint:
/api/stock/{id}
- Method: GET
- Response:
{ "name": "Apple Inc." "price": 150, "company":"Apple" }
Get a list of all available stocks.
- Endpoint:
/api/stock
- Method: GET
- Response:
{ "stockid":1, "name": "Apple Inc.", "price": 150, "company":"Apple" }, // Other stock objects
Create a new stock entry.
- Endpoint:
/api/newstock
- Method: POST
- Response:
{ "id": 1, "message": "stock created successfully", }
- Sample Request:
Update information about a specific stock by providing its ID.
- Endpoint:
/api/stock/{id}
- Method: PUT
- Response:
{ "id": 1, "message": "stock created successfully", }
- Sample Request:
Delete a stock entry by providing its ID.
To run the StocksAPI on your local machine, follow these steps:
- Clone this repository.
- Make sure you have Go (Golang) installed on your system.
- Run the following command to start the server:
go run main.go
- The API will be accessible at http://localhost:8000
- To be able to create the necessary SQL table, you need to execute these commands in the postgresql docker:
psql -U grealyve -d stockapi
CREATE DATABASE stockapi;
CREATE TABLE stocks(stockid SERIAL PRIMARY KEY, name TEXT, price INT, company TEXT);
Feel free to use and modify this API for your own projects. You can integrate it with databases, add authentication, and more. If you encounter any issues or have suggestions, please open an issue on this repository.
https://youtu.be/1nLH4J-DRLg?list=PL5dTjWUk_cPYztKD7WxVFluHvpBNM28N9