Submit templates for repl.it/templates here.

← Back to all posts
REST API template with Express
LOLMcman (68)

Description

This is a simple REST API created with the popular web framework Express. It can perform all CRUD (Create, Read, Update, Delete) operations and follows the REST architectural style.

Features

  • GET, POST, PUT, DELETE request handling
  • Highly scalable MongoDB database
  • Easy to use and understand

EDIT: I forgot to include how to use this so here it is:

Using the API

  • Send GET request to /api/people to get all current objects and /api/people/:person_id to get single object
  • Send POST request to /api/people with a name parameter to create object
  • Send PUT request to /api/people/:person_id with new name parameter to update object
  • Send DELETE request to /api/people/:person_id to delete the desired object
Comments
hotnewtop
ARJPEG (149)

MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string. at new MongooseError (/home/runner/uef0rwtolt/node_modules/mongoose/lib/error/mongooseError.js:10:11) at NativeConnection.Connection.openUri (/home/runner/uef0rwtolt/node_modules/mongoose/lib/connection.js:579:11) at Mongoose.connect (/home/runner/uef0rwtolt/node_modules/mongoose/lib/index.js:333:15) at /home/runner/uef0rwtolt/index.js:19:10 at Script.runInContext (vm.js:131:20) at Object.<anonymous> (/run_dir/interp.js:156:20) at Module._compile (internal/modules/cjs/loader.js:1156:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10) at Module.load (internal/modules/cjs/loader.js:1000:32) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)

LOLMcman (68)

@adityaru When are you getting this

ARJPEG (149)

@LOLMcman At the start, it also says Cannot GET /

LOLMcman (68)

@adityaru It says Cannot GET / because this is an api not a website. Read the 'how to use this api' section in my post for more details. For the first part, I'm still not sure how you're getting the error because it's working fine for me.

LOLMcman (68)

@adityaru Is it after forking the repl?

ARJPEG (149)

oh wait it works when i open the repl in a new tab, just not in the preview