Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
prisma rename project.prisma -> schema.prisma Jul 9, 2019
src remove cleanup as it is no longer needed Jun 27, 2019 rename Photon JS to Photon.js (#186) Aug 12, 2019
package.json add ts-node as dev dep Jun 26, 2019

REST API Example

This example shows how to implement a REST API using Express.JS and Photon.js.

How to use

1. Download example & install dependencies

Clone the repository:

git clone

Install Node dependencies:

cd photonjs/examples/javascript/rest-express
npm install

2. Install the Prisma 2 CLI

To run the example, you need the Prisma 2 CLI:

npm install -g prisma2

3. Set up database

For this example, you'll use a simple SQLite database. To set up your database, run:

prisma2 lift save --name 'init'
prisma2 lift up

You can now use the SQLite Browser to view and edit your data in the ./prisma/dev.db file that was created when you ran prisma2 lift up.

4. Generate Photon (type-safe database client)

Run the following command to generate Photon.js:

prisma2 generate

Now you can seed your database using the seed script from package.json:

npm run seed

5. Start the REST API server

npm run start

The server is now running on http://localhost:3000. You can send the API requests implemented in index.js, e.g. http://localhost:3000/feed.

6. Using the REST API


  • /post/:id: Fetch a single post by its id
  • /feed: Fetch all published posts
  • /filterPosts?searchString={searchString}: Filter posts by title or content


  • /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
  • /user: Create a new user
    • Body:
      • email: String (required): The email address of the user
      • name: String (optional): The name of the user


  • /publish/:id: Publish a post by its id


  • /post/:id: Delete a post by its id

Next steps

You can’t perform that action at this time.