mariem
mariem

Reputation: 56

create Nodejs/Express API to connect to React-Admin frontend Framework

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}!`),
);

Upvotes: 1

Views: 4621

Answers (2)

mariem
mariem

Reputation: 56

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

Upvotes: 1

Nick Nelson
Nick Nelson

Reputation: 152

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.

Upvotes: 2

Related Questions