Svjard / wordle-api

Lighweight serverless API used for Wordle game as part of Javascript series cirriculum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wordle API

This is a simple serverless API designed to generate random words for use in a Wordle clone used in my Javascript classes. It also does checks against words entered the game to verify they are a valid word.

Usage

Deployment

$ serverless deploy

After deploying, you should see output similar to:

Running "serverless" from node_modules

Deploying wordle-api to stage dev (us-east-1)

✔ Service deployed to stack wordle-api-dev (172s)

endpoints:
  GET - https://oxmi6xnm5b.execute-api.us-east-1.amazonaws.com/generate
  GET - https://oxmi6xnm5b.execute-api.us-east-1.amazonaws.com/verify/{word}
functions:
  generate: wordle-api-dev-generate (28 MB)
  verify: wordle-api-dev-verify (28 MB)

The API is public and accessible by anyone.

Invocation

After successful deployment, the API endpoints can be invoked via HTTP:

  1. Generate
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/generate?length=5

Which should result in response similar to the following:

{
  "word": "roofs"
}
  1. Verify
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/verify/<word>

Which should result in response similar to the following:

{
  "exists":true
}

Local development

You can invoke your function locally by using the following command:

serverless invoke local --function generate

Which should result in response similar to the following:

{
  "statusCode": 200,
  "body": "{\n  \"word\": \"roofs\"}"
}

Alternatively, it is also possible to emulate API Gateway and Lambda locally by using serverless-offline plugin. In order to do that, execute the following command:

serverless plugin install -n serverless-offline

It will add the serverless-offline plugin to devDependencies in package.json file as well as will add it to plugins in serverless.yml.

After installation, you can start local emulation with:

serverless offline

About

Lighweight serverless API used for Wordle game as part of Javascript series cirriculum


Languages

Language:JavaScript 100.0%