1componentDidMount() {
2 // Simple POST request with a JSON body using fetch
3 const requestOptions = {
4 method: 'POST',
5 headers: { 'Content-Type': 'application/json' },
6 body: JSON.stringify({ title: 'React POST Request Example' })
7 };
8 fetch('https://jsonplaceholder.typicode.com/posts', requestOptions)
9 .then(response => response.json())
10 .then(data => this.setState({ postId: data.id }));
11}