Skip to content

Commit

Permalink
feat(FirebaseAxios): create and test post request to Firebase with Axios
Browse files Browse the repository at this point in the history
  • Loading branch information
antekai committed Oct 18, 2018
1 parent 5c4a1ba commit 2a62e86
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"antd": "^3.10.1",
"axios": "^0.18.0",
"babel-plugin-import": "^1.9.1",
"react": "^16.5.2",
"react-app-rewired": "^1.6.2",
Expand Down
15 changes: 15 additions & 0 deletions src/Map/Screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./Screen.css";
import { MapLocation } from "./Location";
import { LocationModal } from "./LocationModal";
import { Marker } from "react-google-maps";
import { fireBaseInstance } from "../axios";
const mockData = [
{
id: 0,
Expand Down Expand Up @@ -129,6 +130,13 @@ class MapScreen extends React.Component {
loadMockData = () => {
this.setState({ data: mockData });
};
postToFirebase = () => {
const { data } = this.state;
fireBaseInstance
.post("/fbData.json", data)
.then(response => console.log(response))
.catch(error => console.log(error));
};

render() {
// console.log(this.state.data);
Expand Down Expand Up @@ -177,6 +185,13 @@ class MapScreen extends React.Component {
<Button type="ghost" className="margin-1" onClick={this.loadMockData}>
Load mockData
</Button>
<Button
type="ghost"
className="margin-1"
onClick={this.postToFirebase}
>
postToFirebase
</Button>
<Button type="danger" className="margin-1" onClick={this.removeAll}>
Remove all
</Button>
Expand Down
8 changes: 8 additions & 0 deletions src/axios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from "axios";

// Firebase instance
export const fireBaseInstance = axios.create({
baseURL: "https://react-map-app-f2045.firebaseio.com/"
});

fireBaseInstance.defaults.headers.post["Content-Type"] = "application/json";
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,13 @@ aws4@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"

axios@^0.18.0:
version "0.18.0"
resolved "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"
dependencies:
follow-redirects "^1.3.0"
is-buffer "^1.1.5"

axobject-query@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.0.1.tgz#05dfa705ada8ad9db993fa6896f22d395b0b0a07"
Expand Down Expand Up @@ -4096,7 +4103,7 @@ flush-write-stream@^1.0.0:
inherits "^2.0.1"
readable-stream "^2.0.4"

follow-redirects@^1.0.0:
follow-redirects@^1.0.0, follow-redirects@^1.3.0:
version "1.5.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.9.tgz#c9ed9d748b814a39535716e531b9196a845d89c6"
dependencies:
Expand Down

0 comments on commit 2a62e86

Please sign in to comment.