https://github.com/arup-g/rest-api
REST API built with Go
https://github.com/arup-g/rest-api
goalng rest-api
Last synced: 3 months ago
JSON representation
REST API built with Go
- Host: GitHub
- URL: https://github.com/arup-g/rest-api
- Owner: ARUP-G
- Created: 2023-07-28T12:26:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-03T07:19:29.000Z (over 1 year ago)
- Last Synced: 2025-01-23T07:45:47.527Z (4 months ago)
- Topics: goalng, rest-api
- Language: Go
- Homepage:
- Size: 7.85 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# REST API in Golang
This is a simple REST API built with Go that allows you to perform CRUD (Create, Read, Update, Delete) operations on a collection of items.
## Features
- **GET All Items**: Retrieve a list of all items.
- **GET Item by ID**: Retrieve a specific item by its unique ID.
- **POST New Item**: Create a new item and add it to the collection.
- **UPDATE Item**: Update an existing item's information.
- **DELETE Item**: Remove an item from the collection.## Installation
1. Make sure you have Go installed on your system.
2. Clone this repository:
```shell
git clone https://github.com/ARUP-G/REST-API.git3. Build and run the application:
```shell
go build
./REST-API4. The API server will be running at http://localhost:9000.
## Usage
### GET All Books- **Endpoint**: /api/books
- **Method**: `GET`
- **Description**: Retrieve a list of all books.
- **Example Response**:
```json
[
{
"id": "1",
"isbn": "86348",
"title": "Book1",
"author": {
"fname": "Ryan",
"lname": "Gosling"
}
},
{
"id": "2",
"isbn": "85578",
"title": "Book2",
"author": {
"fname": "Arup",
"lname": "Das"
}
}
]
```### GET Books by ID
- **Endpoint**: /api/books/{id}
- **Method**: `GET`
- **Description**: Retrieve a specific book by its unique ID.
- **Example Request**: /api/books/2
- **Example Response**:
```json
{
"id": "2",
"isbn": "85578",
"title": "Book2",
"author": {
"fname": "Arup",
"lname": "Das"
}
}
```
### Create Books
- **Endpoint**: /api/books
- **Method**: `POST`
- **Description**: Create a new book and add it to the collection.
- **Example Request**: /api/books- **Example Request Body**
```json
{
"isbn": "90078",
"title": "New Book",
"author": {
"fname": "Chilian",
"lname": "Murphy"
}
}
```
- **Example Response**:
```json
{
"id": "60",
"isbn": "90078",
"title": "New Book",
"author": {
"fname": "Chilian",
"lname": "Murphy"
}
}
```### Update Book
- **Endpoint**: /api/books/{id}
- **Method**: `UPDATE`
- **Description**: Update existing book and add it to the collection.
- **Example Request**: /api/books/60
- **Example Request Body**
```json
{
"isbn": "90078",
"title": "Updated Book",
"author": {
"fname": "Chilian",
"lname": "Murphy"
}
}
```
- **Example Response**:
```json
{
"id": "60",
"isbn": "90078",
"title": "Updated Book",
"author": {
"fname": "Chilian",
"lname": "Murphy"
}
}
```### Delete Book
- **Endpoint**: /api/books/{id}
- **Method**: `DELETE`
- **Description**: Delete a book from the collection.
- **Example Request**: /api/books/0
- **Example Request Body**
Deleted