Skip to content

Commit 20cbcc0

Browse files
authored
Merge pull request #1 from thenderson55/api
Heroku approves, so merging.
2 parents bb467a3 + a97f6bd commit 20cbcc0

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const app = express();
44

55
app.use(express.static(path.join(`${__dirname}/build`)));
66

7-
const port = process.env.PORT || 3000;
7+
const port = process.env.PORT || 5000;
88

99
const server = app.listen(port,()=>{
1010
process.stdout.write(`App listening on port ${port}!\n Press CTR C to stop the server`)

src/App.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import logo from './logo.svg';
3+
import ChucksJoke from './ChucksJoke'
34
import './App.css';
45

56
function App() {
67
return (
78
<div className="App">
89
<header className="App-header">
910
<img src={logo} className="App-logo" alt="logo" />
11+
<ChucksJoke />
1012
<p>
1113
Edit <code>src/App.js</code> and save to reload.
1214
</p>

src/ChucksJoke.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from "react";
2+
3+
export default class ApiOne extends React.Component {
4+
constructor() {
5+
super();
6+
this.state = {
7+
joke: []
8+
};
9+
}
10+
11+
componentDidMount() {
12+
const myHeaders = new Headers();
13+
myHeaders.append(
14+
"X-RapidAPI-Host",
15+
"matchilling-chuck-norris-jokes-v1.p.rapidapi.com"
16+
);
17+
myHeaders.append(
18+
"X-RapidAPI-Key",
19+
"5456615b4cmsh40eaeb350692ccep17bbe1jsn2758aaa3f720"
20+
);
21+
myHeaders.append("accept", "application/json");
22+
23+
const myInit = { method: "GET", headers: myHeaders };
24+
25+
const myRequest = new Request(
26+
"https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random",
27+
myInit
28+
);
29+
30+
fetch(myRequest)
31+
.then(res => res.json())
32+
.then(data =>
33+
this.setState({
34+
joke: data.value
35+
})
36+
);
37+
}
38+
39+
render() {
40+
return (
41+
<div className="container">
42+
<h1>
43+
Ready to have your mind blown and be destroyed by a single Chuck
44+
Norris joke!
45+
</h1>
46+
<h2>{this.state.joke}</h2>
47+
</div>
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)