Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rest-express-auth example #2869

Draft
wants to merge 22 commits into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dc060df
chore: initial rest-express-auth creation
gautvm May 18, 2021
6b9a670
refactor: create data models
gautvm May 18, 2021
fb38fef
refactor: set up api structure
gautvm May 18, 2021
f14f40c
refactor: start some work on signup
gautvm May 18, 2021
e151438
feat(rest-express-auth) add signup route
gautvm May 18, 2021
67a3158
feat(rest-express-auth) add login route
gautvm May 18, 2021
df0b5d8
feat(rest-express-auth) added logout route
gautvm May 18, 2021
35faffb
refactor(rest-express-auth) refactor isAuth middleware
gautvm May 18, 2021
d0324e5
feat(rest-express-auth) add account delete route
gautvm May 19, 2021
c10c571
feat(rest-express-auth): posts get route
gautvm Jun 4, 2021
6bc4221
added readmes to rest-express-auth
ruheni Jun 21, 2021
cf802ea
Merge branch 'prisma:latest' into rest-express-auth
Mar 7, 2023
e5bd3a2
fix: implemented fixes from review
gautvm Mar 7, 2023
ea1dbd3
refactor updated rest-express-auth example to follow the format of ot…
gautvm Mar 7, 2023
18e37d1
refactor: added database seeding
gautvm Mar 7, 2023
e48bfc5
fix: corrected readme
Mar 7, 2023
9e56be0
fix: added isAuthenticated middleware to routes
Mar 7, 2023
ad62f59
fix: rest-express-auth: fixed readmes
gautvm Mar 20, 2023
78494c3
fix: rest-express-auth: correct protected routes
gautvm Mar 20, 2023
9d82677
refactor: rest-express-auth: add test
gautvm Mar 20, 2023
6df2873
fix: rest-express-auth: add hashing for passwords in seeding data
gautvm Mar 20, 2023
90e30d7
docs: rest-express-auth: add docs for isAuthenticated middleware
gautvm May 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/readmes/_using-the-rest-api-auth.md
gautvm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Using the REST API

You can access the REST API of the server using the following endpoints:

### `GET`

- `/post/:id`: Fetch a single post by its `id`
- `/feed?searchString={searchString}&take={take}&skip={skip}&orderBy={orderBy}`: Fetch all _published_ posts
- Query Parameters
- `searchString` (optional): This filters posts by `title` or `content`
- `take` (optional): This specifies how many objects should be returned in the list
- `skip` (optional): This specifies how many of the returned objects in the list should be skipped
- `orderBy` (optional): The sort order for posts in either ascending or descending order. The value can either `asc` or `desc`
- `/user/:id/drafts`: Fetch user's drafts by their `id`
- `/users`: Fetch all users
### `POST`

- `/post`: Create a new post
- Body:
- `title: String` (required): The title of the post
- `content: String` (optional): The content of the post
- `authorEmail: String` (required): The email of the user that creates the post
- `/signup`: Create a new user
- Body:
- `email: String` (required): The email address of the user
- `name: String` (optional): The name of the user
- `postData: PostCreateInput[]` (optional): The posts of the user

### `PUT`

- `/publish/:id`: Toggle the publish value of a post by its `id`
- `/post/:id/views`: Increases the `viewCount` of a `Post` by one `id`

### `DELETE`

- `/post/:id`: Delete a post by its `id`
40 changes: 40 additions & 0 deletions .github/readmes/typescript/rest-express-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# REST API with Authentication

This example shows how to implement a **GraphQL server with TypeScript** with the following stack:
gautvm marked this conversation as resolved.
Show resolved Hide resolved

- [**Express**](https://expressjs.com/): Web framework for building Node.js web applications
- [**Prisma Client**](https://www.prisma.io/docs/concepts/components/prisma-client): Databases access (ORM)
- [**Prisma Migrate**](https://www.prisma.io/docs/concepts/components/prisma-migrate): Database migrations
- [**SQLite**](https://www.sqlite.org/index.html): Local, file-based SQL database

## Contents

- [Getting Started](#getting-started)
- [Using the GraphQL API](#using-the-rest-api)
gautvm marked this conversation as resolved.
Show resolved Hide resolved
- [Evolving the app](#evolving-the-app)
- [Switch to another database (e.g. PostgreSQL, MySQL, SQL Server)](#switch-to-another-database-eg-postgresql-mysql-sql-server)
- [Next steps](#next-steps)

__INLINE(../_setup-0.md)__
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/typescript/rest-express-auth
__INLINE(../_setup-1.md)__
cd rest-express-auth
__INLINE(../_setup-2.md)__
cd prisma-examples/typescript/rest-express-auth
__INLINE(../_setup-3.md)__

### 3. Start the REST API server

```
npm run dev
```

The server is now running on `http://localhost:3000`. You can now the API requests, e.g. [`http://localhost:3000/feed`](http://localhost:3000/feed).

__INLINE(../../_using-the-rest-api.md)__

__INLINE(../_evolving-the-app-rest.md)__

__INLINE(../../_switching-databases.md)__

__INLINE(../../_next-steps.md)__