https://github.com/edmartt/go-rest-exercise
A simple exercise for learning http with Go
https://github.com/edmartt/go-rest-exercise
Last synced: over 1 year ago
JSON representation
A simple exercise for learning http with Go
- Host: GitHub
- URL: https://github.com/edmartt/go-rest-exercise
- Owner: Edmartt
- Created: 2022-03-27T10:28:33.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-27T10:31:12.000Z (about 4 years ago)
- Last Synced: 2025-01-23T18:49:20.461Z (over 1 year ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple web service example
A simple exercise for learning about http, rest api in Go language.
## Steps for start this project
```
git clone https://github.com/edmartt/go-rest-exercise
```
```
go get github.com/gorilla/mux
```
```
go run main.go
```
## Request examples
- Get all articles
```
curl -i -H "Content-Type: application/json" http://localhost:8081/articles
```
- Get a single article
```
curl -i -H "Content-Type: application/json" http://localhost:8081/article/1
```
- Create new article
```
curl -i -X POST -H "Content-Type: application/json" -d '{"id":"3", "title": "My new title", "desc": "My new desc", "content": "My new content"}' http://localhost:8081/article
```
- Update an article
```
curl -i -X PUT -H "Content-Type: application/json" -d '{"title":"alice", "desc": "fantasy book", "content": "ilustrations"}' http://localhost:8081/article/2
```
- Delete an article
```
curl -i -X DELETE -H "Content-Type: application/json" http://localhost:8081/article/1
```