Building an app like Uber using React-Native

Madhu Naidu
2 min readJun 14, 2019

--

Part 2: Flow for creating REST api

We will start with user api as an example to see how to create our api’s. The flow for driver, trip and cab api’s is similar to the user api and can be taken from github.

Every module will have the following files.

  1. app.js: This is main file and needed to start the node server
  2. /routes/route.js: This file will receive all incoming requests and route to respective files
  3. /routes/user.js : This will act as the servlet/controller to receive the request and return respective response
  4. /dao/user.js: This will do the task of persisting data into database or fetching data from database
  5. /util/util.js: This will consist of functions having common code

So let’s look at each file described above

Our app.js looks like

app.js

Our user.js file used to receive the requests and return response looks like this.

/routes/route.js

Our user.js responsible for saving and fetching data is

/dao/user.js

As you can see we are using ‘diskdb’ an in-memory file database to store our data. The datbase name is saved as emp_user in this case

Once the above changes are done the server can be started using ‘npm start’ from command line.

The server will start running on “localhost:5000”

node server

The source code in github consists of all api’s. These api’s can be tested either from browser or Postman tool

This is a simple server code for our React Native app. This NodeJS code does not cover actual database, will not be able to scale. There is no security included.

In the next part lets look into how to deploy our NodeJS server

--

--

Madhu Naidu

An enthusiastic developer interested in taking up challenges in my daily life