1

react-admin Is a frontend Framework for building admin applications running in the browser on top of REST/GraphQL APIs, using ES6, React and Material Design. Previously named admin-on-rest. Open sourced and maintained by marmelab.

I'm trying to create and configure a Rest API (backend) using Nodejs/Express, I want to know how to configure the requests and the endpoints in my express API.

const express = require('express')
const app = express()
const bodyParser = require('body-parser');
const cors = require('cors');
const port = 80;
app.use(express.json());
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});
app.get('/', (req, res) => {
  return res.send('Received a GET HTTP method');
});
app.post('/', (req, res) => {
  return res.send('Received a POST HTTP method');
});
app.put('/', (req, res) => {
  return res.send('Received a PUT HTTP method');
});
app.delete('/', (req, res) => {
  return res.send('Received a DELETE HTTP method');
});
app.listen(port, () =>
  console.log(`Example app listening on port ${port}!`),
);
2
  • Can you add more info about what would you like to do, what is your database and so on? Or problem is just a create router for your application? Maybe you can specify what kind of resources you are what to access with API... Commented Jul 2, 2019 at 16:58
  • my Database is Postgresql and my Server is NodeJs/express and I want to create a full stuck web application with the frontend react-admin Commented Jul 3, 2019 at 15:38

2 Answers 2

2

This depends on which react-admin data provider you are using. Data providers work as an adapter between react-admin and the specific API you use. There is no "standard" API specification for react-admin.

There is an example ra-data-simple-rest which might suit your needs if you really want to write your own API from scratch in Express.

The better solution might be to use something like Feathers and feathers-postgresql for your API, and then use the existing data provider ra-data-feathers to connect react-admin to Feathers.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot for your help @Nick Nelson, I thought that I have to create a Rest Cient not a Data Provider what's the difference between them ?
The marmelab.com/admin-on-rest/RestClients.html link is for admin-on-rest. admin-on-rest was renamed to react-admin at version 2. Rest Client and Data Provider are basically the same thing in this context. The only difference is that Rest Client is for admin-on-rest and Data Provider is for react-admin. I'd suggest staying away from the admin-on-rest documentation when working with react-admin. There are significant changes between the two, and mixing the documentation is likely to get confusing.
Hello @nick, I'm still confused in the way to make this project work correctly, Actually I want to create from scratch a NodeJs/Express server with database Postgres but it seems that I have to create a DataProvider ... and I have no idea how to do that ... is there any examples of full stack project with react-admin that can help me ... because I can't found such a project !!
You don't have to create a DataProvider. You could write an API that conforms to the standards expected by an existing DataProvider like ra-data-json-server or ra-data-simple-rest.
I'd suggest you start with the react-admin tutorial which will show you how to set up a simple react-admin project using the ra-data-simple-rest data provider and an existing API, and then look at a tutorial on writing an API with Express like this. Doing both of those should give you everything you need to then combine the two, so your react-admin app connects to your Express API.
1

THIS PROJECT PERFECTLY ANSWERS MY QUESTION (except that it use mongodb). Thank you Michalak111

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.