Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restful-go: update ex-3 instructions and solution #56

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions restful-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Here are some examples of opensource frameworks:

Using the standard library to create a client that calls your new web endpoint. To connect to you server, you will need to run your server in one different and the client app in a different terminal window.

_Extra Practice:_ Lots of companies use [Postman](https://www.postman.com/) to test their service endpoints. Build a client in postman that will call your server. Save you postman solution and generate a go client from the [Postman UI](<F5>nhttps://learning.postman.com/docs/sending-requests/generate-code-snippets/). Does you generated go code match the one you build?

### [Exercise 4](/ex-4-test/framework_tests.go)

Using the [httptest](https://pkg.go.dev/net/http/httptest#example-ResponseRecorder) package add some tests for at least one of our newly created endpoints. You should have one test that checks for a 200s class error and one that tests for a 400s class error. Add additional test validations as time allows.
Expand Down
24 changes: 24 additions & 0 deletions restful-go/ex-3-clients/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"net/http"
"time"
)

func main() {

client := http.Client{
Timeout: time.Second * 2,
}

req, err := http.NewRequest("GET", "http://localhost:3000/3weeks-go/testGet", nil)
if err != nil {
panic(err)
}
body, err := client.Do(req)
if err != nil {
panic(err)
}
fmt.Println(body)
}
Loading