commit 2c3df630d814d9be850abea450d07dadfcb79e06 Author: dadgam3er Date: Fri Sep 20 17:21:36 2024 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0a499b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.encore +encore.gen.go +encore.gen.cue diff --git a/README.md b/README.md new file mode 100644 index 0000000..20e1175 --- /dev/null +++ b/README.md @@ -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 ./... +``` \ No newline at end of file diff --git a/encore.app b/encore.app new file mode 100644 index 0000000..263e1e1 --- /dev/null +++ b/encore.app @@ -0,0 +1,5 @@ +{ + // The app is not currently linked to the encore.dev platform. + // Use "encore app link" to link it. + "id": "", +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c354830 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module encore.app + +go 1.18 + +require encore.dev v1.37.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c778603 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +encore.dev v1.37.0 h1:of8TTr+SEPHb9riB6feibBa/6mjbaElVd519pOK026w= +encore.dev v1.37.0/go.mod h1:XdWK6bKKAVzutmOKpC5qzalDQJLNfRCF/YCgA7OUZ3E= diff --git a/hello/hello.go b/hello/hello.go new file mode 100644 index 0000000..7a04761 --- /dev/null +++ b/hello/hello.go @@ -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 diff --git a/hello/hello_test.go b/hello/hello_test.go new file mode 100644 index 0000000..dfd56ba --- /dev/null +++ b/hello/hello_test.go @@ -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) + } +}