Initial commit
This commit is contained in:
commit
2c3df630d8
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/.encore
|
||||||
|
encore.gen.go
|
||||||
|
encore.gen.cue
|
||||||
48
README.md
Normal file
48
README.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# REST API Starter
|
||||||
|
|
||||||
|
This is a RESTful API Starter with a single Hello World API endpoint.
|
||||||
|
|
||||||
|
## Developing locally
|
||||||
|
|
||||||
|
When you have [installed Encore](https://encore.dev/docs/install), you can create a new Encore application and clone this example with this command.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
encore app create my-app-name --example=hello-world
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running locally
|
||||||
|
```bash
|
||||||
|
encore run
|
||||||
|
```
|
||||||
|
|
||||||
|
While `encore run` is running, open [http://localhost:9400/](http://localhost:9400/) to view Encore's [local developer dashboard](https://encore.dev/docs/observability/dev-dash).
|
||||||
|
|
||||||
|
## Using the API
|
||||||
|
|
||||||
|
To see that your app is running, you can ping the API.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl http://localhost:4000/hello/World
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
Deploy your application to a staging environment in Encore's free development cloud:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add -A .
|
||||||
|
git commit -m 'Commit message'
|
||||||
|
git push encore
|
||||||
|
```
|
||||||
|
|
||||||
|
Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL.
|
||||||
|
|
||||||
|
From there you can also connect your own AWS or GCP account to use for deployment.
|
||||||
|
|
||||||
|
Now off you go into the clouds!
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
encore test ./...
|
||||||
|
```
|
||||||
5
encore.app
Normal file
5
encore.app
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
// The app is not currently linked to the encore.dev platform.
|
||||||
|
// Use "encore app link" to link it.
|
||||||
|
"id": "",
|
||||||
|
}
|
||||||
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module encore.app
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require encore.dev v1.37.0 // indirect
|
||||||
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
encore.dev v1.37.0 h1:of8TTr+SEPHb9riB6feibBa/6mjbaElVd519pOK026w=
|
||||||
|
encore.dev v1.37.0/go.mod h1:XdWK6bKKAVzutmOKpC5qzalDQJLNfRCF/YCgA7OUZ3E=
|
||||||
59
hello/hello.go
Normal file
59
hello/hello.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// Service hello implements a simple hello world REST API.
|
||||||
|
package hello
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Welcome to Encore!
|
||||||
|
// This is a simple "Hello World" project to get you started.
|
||||||
|
//
|
||||||
|
// To run it, execute "encore run" in your favorite shell.
|
||||||
|
|
||||||
|
// ==================================================================
|
||||||
|
|
||||||
|
// This is a public REST API that responds with a personalized greeting.
|
||||||
|
// Learn more about defining APIs with Encore:
|
||||||
|
// https://encore.dev/docs/primitives/services-and-apis
|
||||||
|
//
|
||||||
|
// To call it, run in your terminal:
|
||||||
|
//
|
||||||
|
// curl http://localhost:4000/hello/World
|
||||||
|
//
|
||||||
|
//encore:api public path=/hello/:name
|
||||||
|
func World(ctx context.Context, name string) (*Response, error) {
|
||||||
|
msg := "Hello, " + name + "!"
|
||||||
|
return &Response{Message: msg}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================================================================
|
||||||
|
|
||||||
|
// Encore comes with a built-in local development dashboard for
|
||||||
|
// exploring your API, viewing documentation, debugging with
|
||||||
|
// distributed tracing, and more:
|
||||||
|
//
|
||||||
|
// http://localhost:9400
|
||||||
|
//
|
||||||
|
|
||||||
|
// ==================================================================
|
||||||
|
|
||||||
|
// Next steps
|
||||||
|
//
|
||||||
|
// 1. Deploy your application to the cloud
|
||||||
|
//
|
||||||
|
// git add -A .
|
||||||
|
// git commit -m 'Commit message'
|
||||||
|
// git push encore
|
||||||
|
//
|
||||||
|
// 2. To continue exploring Encore, check out one of these topics:
|
||||||
|
//
|
||||||
|
// Defining APIs and Services: https://encore.dev/docs/primitives/services-and-apis
|
||||||
|
// Using SQL databases: https://encore.dev/docs/develop/databases
|
||||||
|
// Authenticating users: https://encore.dev/docs/develop/auth
|
||||||
|
// Building a Slack bot: https://encore.dev/docs/tutorials/slack-bot
|
||||||
|
// Building a REST API: https://encore.dev/docs/tutorials/rest-api
|
||||||
|
// Building an Event-Driven app: https://encore.dev/docs/tutorials/uptime
|
||||||
22
hello/hello_test.go
Normal file
22
hello/hello_test.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package hello
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Run tests using `encore test`, which compiles the Encore app and then runs `go test`.
|
||||||
|
// It supports all the same flags that the `go test` command does.
|
||||||
|
// You automatically get tracing for tests in the local dev dash: http://localhost:9400
|
||||||
|
// Learn more: https://encore.dev/docs/develop/testing
|
||||||
|
func TestWorld(t *testing.T) {
|
||||||
|
const in = "Jane Doe"
|
||||||
|
resp, err := World(context.Background(), in)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := resp.Message; !strings.Contains(got, in) {
|
||||||
|
t.Errorf("World(%q) = %q, expected to contain %q", in, got, in)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user