|
| 1 | +# Encore + Prisma TypeScript Example |
| 2 | + |
| 3 | +This is a RESTful API Starter with [Prisma](https://prisma.io) as ORM to handle database CRUD operations. |
| 4 | + |
| 5 | +## Developing locally |
| 6 | + |
| 7 | +When you have [installed Encore](https://encore.dev/docs/install), you can create a new Encore application and clone this example with this command. |
| 8 | + |
| 9 | +```bash |
| 10 | +encore app create my-app-name --example=ts/prisma |
| 11 | +``` |
| 12 | + |
| 13 | +## Running locally |
| 14 | + |
| 15 | +```bash |
| 16 | +encore run |
| 17 | +``` |
| 18 | + |
| 19 | +While `encore run` is running, open <http://localhost:9400/> to view Encore's [local developer dashboard](https://encore.dev/docs/observability/dev-dash). |
| 20 | + |
| 21 | +## Configure Prisma |
| 22 | + |
| 23 | +Get the connection string to the shadow database by running: |
| 24 | + |
| 25 | +``` |
| 26 | +encore db conn-uri encore_prisma_test --shadow |
| 27 | +
|
| 28 | +``` |
| 29 | + |
| 30 | +Then edit `users/prisma/schema.prisma` replace `<paste shadow db connection string here>` with the output of the above command. |
| 31 | + |
| 32 | + |
| 33 | +## Using the API |
| 34 | + |
| 35 | +Counts and returns the number of existing users |
| 36 | + |
| 37 | +```bash |
| 38 | +curl 'http://localhost:4000/count/users' |
| 39 | +``` |
| 40 | + |
| 41 | +Create a new user |
| 42 | + |
| 43 | +```bash |
| 44 | +curl 'http://localhost:4000/users' -d '{"name":"John","surname":"Doe"}' |
| 45 | +``` |
| 46 | + |
| 47 | +Get all users data |
| 48 | + |
| 49 | +```bash |
| 50 | +curl 'http://localhost:4000/users' |
| 51 | + |
| 52 | +# for paginated data: |
| 53 | +curl 'http://localhost:4000/users?page=1&limit=10' |
| 54 | +``` |
| 55 | + |
| 56 | +Get user data by id |
| 57 | + |
| 58 | +```bash |
| 59 | +curl 'http://localhost:4000/users/:id' |
| 60 | +``` |
| 61 | + |
| 62 | +Update user data |
| 63 | + |
| 64 | +```bash |
| 65 | +# partial update |
| 66 | +curl -XPATCH 'http://localhost:4000/users/:id' -d '{"data":{"name":"Johnny"}}' |
| 67 | + |
| 68 | +# update complete data |
| 69 | +curl -XPATCH 'http://localhost:4000/users/:id' -d '{"data":{"name":"Mary","surname":"Jane"}}' |
| 70 | +``` |
| 71 | + |
| 72 | +Delete an user by id |
| 73 | + |
| 74 | +```bash |
| 75 | +curl -X DELETE 'http://localhost:4000/users/:id' |
| 76 | +``` |
| 77 | + |
| 78 | +## Deployment |
| 79 | + |
| 80 | +Deploy your application to a staging environment in Encore's free development cloud: |
| 81 | + |
| 82 | +```bash |
| 83 | +git add -A . |
| 84 | +git commit -m 'Commit message' |
| 85 | +git push encore |
| 86 | +``` |
| 87 | + |
| 88 | +Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL. |
| 89 | + |
| 90 | +From there you can also connect your own AWS or GCP account to use for deployment. |
| 91 | + |
| 92 | +Now off you go into the clouds! |
0 commit comments