An open API service indexing awesome lists of open source software.

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

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
```