Skip to content

Commit

Permalink
Merge pull request #229 from poteto-go/20250213/rel2
Browse files Browse the repository at this point in the history
20250213/rel2
  • Loading branch information
poteto0 authored Feb 13, 2025
2 parents b36bf50 + b0652b6 commit 151abdc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# 1.x.x

## 1.4.X

### 1.4.0

- FEAT: `response` fullfill interface for `ReponseController` by @poteto0 in #226
- FEAT: `poteto.Play` for ut w/o server by @poteto0 in #226

KEYNOTE:
```go
func main() {
p := poteto.New()

p.GET("/users", func(ctx poteto.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{
"id": "1",
"name": "tester",
})
})

res := p.Play(http.MethodGet, "/users")
resBodyStr := res.Body.String
// => {"id":"1","name":"tester"}
}
```

## 1.3.X

### 1.3.6
Expand Down
62 changes: 42 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,25 @@ LISTENER_NETWORK=tcp

## Feature

### JSONRPCAdapter (`>=0.26.0`)
### Test Without Server (`>=1.4.0`)

KeyNote: You can serve JSONRPC server easily.
> [!NOTE]
> Poteto developers can easily test without setting up a server.
```go
type (
Calculator struct{}
AdditionArgs struct {
Add, Added int
}
)

func (tc *TestCalculator) Add(r *http.Request, args *AdditionArgs) int {
return args.Add + args.Added
}

func main() {
p := New()
p := poteto.New()

rpc := TestCalculator{}
// you can access "/add/Calculator.Add"
p.POST("/add", func(ctx Context) error {
return PotetoJsonRPCAdapter[Calculator, AdditionArgs](ctx, &rpc)
})
p.GET("/users", func(ctx poteto.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{
"id": "1",
"name": "tester",
})
})

p.Run("8080")
res := p.Play(http.MethodGet, "/users")
resBodyStr := res.Body.String
// => {"id":"1","name":"tester"}
}
```

Expand Down Expand Up @@ -102,6 +95,35 @@ func handler(ctx poteto.Context) error {
}
```

### JSONRPCAdapter (`>=0.26.0`)

KeyNote: You can serve JSONRPC server easily.

```go
type (
Calculator struct{}
AdditionArgs struct {
Add, Added int
}
)

func (tc *TestCalculator) Add(r *http.Request, args *AdditionArgs) int {
return args.Add + args.Added
}

func main() {
p := New()

rpc := TestCalculator{}
// you can access "/add/Calculator.Add"
p.POST("/add", func(ctx Context) error {
return PotetoJsonRPCAdapter[Calculator, AdditionArgs](ctx, &rpc)
})

p.Run("8080")
}
```

## How to use

```go:main.go
Expand Down

0 comments on commit 151abdc

Please sign in to comment.