|
| 1 | +# Recipes Backend Example |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +This project is a backend service for a recipe management system, built using AWS SAM (Serverless Application Model) and DynamoDB as part of the NERDS stack. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- [Docker Desktop](https://www.docker.com/products/docker-desktop/) |
| 10 | +- [DynamoDB Local Docker Image](https://hub.docker.com/r/amazon/dynamodb-local) |
| 11 | +- [Node v22.3.0](https://nodejs.org/en/blog/release/v22.3.0) |
| 12 | +- [AWS JavaScript SDK v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/) |
| 13 | +- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) |
| 14 | + |
| 15 | +## Setup |
| 16 | + |
| 17 | +1. Install dependencies: |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install |
| 21 | +``` |
| 22 | + |
| 23 | +2. Start the local DynamoDB: |
| 24 | + |
| 25 | +```bash |
| 26 | +npm run start-db |
| 27 | +``` |
| 28 | + |
| 29 | +3. Create the recipes table: |
| 30 | + |
| 31 | +```bash |
| 32 | +npm run create-recipes-table |
| 33 | +``` |
| 34 | + |
| 35 | +4. Build the SAM application: |
| 36 | + |
| 37 | +```bash |
| 38 | +npm run build-backend |
| 39 | +``` |
| 40 | + |
| 41 | +5. Start the local API: |
| 42 | + |
| 43 | +```bash |
| 44 | +npm run start-backend |
| 45 | +``` |
| 46 | + |
| 47 | +# Setup |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +# Creating an user |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +## Available Scripts |
| 56 | + |
| 57 | +- `npm run start-db`: Start local DynamoDB container |
| 58 | +- `npm run stop-db`: Stop and remove local DynamoDB container |
| 59 | +- `npm run create-recipes-table`: Create the recipes table in local DynamoDB |
| 60 | +- `npm run show-tables`: List tables in local DynamoDB |
| 61 | +- `npm run scan-recipes`: Scan all items in the recipes table |
| 62 | +- `npm run build-backend`: Build the SAM application, if you change the code in the `src/*` folder you need to rebuild your project. |
| 63 | +- `npm run start-backend`: Start the local API |
| 64 | +- `npm run create-user`: Create a sample user using curl |
| 65 | + |
| 66 | +## Configuration |
| 67 | + |
| 68 | +The project uses the following configuration (defined in package.json): |
| 69 | + |
| 70 | +- DynamoDB host: `0.0.0.0` |
| 71 | +- DynamoDB port: `8000` |
| 72 | +- API port: `3000` |
| 73 | +- Recipe table name: `recipe_table` |
| 74 | + |
| 75 | +## API Endpoints |
| 76 | + |
| 77 | +- `POST /users`: Create a new user |
| 78 | +- `GET /users/{userId}`: Get user details |
| 79 | +- `PUT /users/{userId}`: Update user details |
| 80 | +- `DELETE /users/{userId}`: Delete a user |
| 81 | +- `POST /recipes`: Create a new recipe |
| 82 | +- `GET /recipes/{recipeId}`: Get recipe details |
| 83 | +- `PUT /recipes/{recipeId}`: Update recipe details |
| 84 | +- `DELETE /recipes/{recipeId}`: Delete a recipe |
| 85 | +- `GET /recipes`: List all recipes |
| 86 | + |
| 87 | +## Development |
| 88 | + |
| 89 | +To start development: |
| 90 | + |
| 91 | +1. Ensure local DynamoDB is running (`npm run start-db`) |
| 92 | +2. Make changes to the Lambda functions in the `src` directory |
| 93 | +3. Rebuild the application (`npm run build-backend`) |
| 94 | +4. Start the local API (`npm run start-backend`) |
| 95 | +5. Test your changes using the provided npm scripts or tools like Postman |
0 commit comments