I have written a Rails API backend. I can see that the endpoint is getting hit by watching my server in my terminal. I can also see a return in Postman. However, I am unable to get a payload returned in my React frontend. Here is my fetch call in React(I have the debuggers in there but they're not getting hit):
handleSearch(video) {
fetch(`http://localhost:3000/api/v1/search?q=${video}`)
.then((response) => {
debugger
return response.json()
})
.then((data) => {
debugger
})
}
Here is my api controller:
def index
videos = VideoService.search_content(params['q'])
render json: videos
end
And here's my output in my terminal server:
Started GET "/api/v1/search?q=Firefly" for 127.0.0.1 at 2017-12-28 11:40:38 -0700
Processing by Api::V1::SearchController#index as */*
Parameters: {"q"=>"Firefly"}
Completed 200 OK in 426ms (Views: 7.5ms | ActiveRecord: 0.0ms)
I'm not really sure what the problem is. I have never had an issue before when making api requests. And like I said. I can see the server being interacted with and can see a payload return in Postman. Thanks for any help!
EDIT: Here is how I'm calling the handleSearch on the way down:
<SideBar
info={this.state.info}
logout={this.handleLogout.bind(this)}
search={this.handleSearch.bind(this)}
/>
And here it is being called in the SideBar component:
searchHandler(video) {
this.props.search(video)
}
<SearchBox search={this.searchHandler.bind(this)}/>
And finally where the input is actually coming in:
handleSearch(e){
let video = e.target.previousSibling.value
this.props.search(video)
}
render() {
return(
<form className="search-box" >
<input type="text" placeholder="Search.." name="search"/>
<button className="fa fa-search" type="submit" onClick={this.handleSearch.bind(this)}>
</button>
</form>
)
}