2016-10-20 20:30:53 +02:00
|
|
|
+++
|
2016-11-17 08:46:00 +02:00
|
|
|
title = "CRUD Example"
|
|
|
|
description = "CRUD (Create, read, update and delete) example for Echo"
|
2016-11-21 00:16:22 +02:00
|
|
|
[menu.main]
|
2016-10-20 20:30:53 +02:00
|
|
|
name = "CRUD"
|
|
|
|
parent = "recipes"
|
|
|
|
weight = 2
|
|
|
|
+++
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Server
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
`server.go`
|
|
|
|
|
|
|
|
{{< embed "crud/server.go" >}}
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Client
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
`curl`
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
### Create User
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
curl -X POST \
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
-d '{"name":"Joe Smith"}' \
|
|
|
|
localhost:1323/users
|
|
|
|
```
|
|
|
|
|
|
|
|
*Response*
|
|
|
|
|
|
|
|
```js
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "Joe Smith"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
### Get User
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
curl localhost:1323/users/1
|
|
|
|
```
|
|
|
|
|
|
|
|
*Response*
|
|
|
|
|
|
|
|
```js
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "Joe Smith"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
### Update User
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
curl -X PUT \
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
-d '{"name":"Joe"}' \
|
|
|
|
localhost:1323/users/1
|
|
|
|
```
|
|
|
|
|
|
|
|
*Response*
|
|
|
|
|
|
|
|
```js
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "Joe"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
### Delete User
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
curl -X DELETE localhost:1323/users/1
|
|
|
|
```
|
|
|
|
|
|
|
|
*Response*
|
|
|
|
|
|
|
|
`NoContent - 204`
|
|
|
|
|
2016-11-17 09:05:37 +02:00
|
|
|
## [Source Code]({{< source "crud" >}})
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Maintainers
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
- [vishr](https://github.com/vishr)
|