Reputation: 107
I am working on an android application that utilizes Retrofit to make api calls. When I call the following code:
String searchText = query;
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://mashape-community-urban-dictionary.p.mashape.com")
.build();
WordsApiService wordsApi = restAdapter.create(WordsApiService.class);
wordsApi.getWordDefinition(query, new Callback<WordsResponse>() {
@Override
public void success(WordsResponse wordsResponse, Response response) {
System.out.println(response.toString());
}
@Override
public void failure(RetrofitError error) {
System.out.println(error.getResponse().getStatus());
}
});
With the following service:
public interface WordsApiService {
@Headers({
"X-Mashape-Key : *insert real api key*",
"Accept: text/plain"
})
@GET("/define/")
void getWordDefinition(@Query("word") String word, Callback<WordsResponse> callback);
}
I am getting a 404 error (retrofit.RetrofitError: 404 Not Found).
When I go into mashape, I see that the service call is going through and hitting the api.
Am I missing something obvious in terms of the configuration of the application?
Upvotes: 2
Views: 8974
Reputation: 1841
Remove the forward slash from the "define" endpoint path.
Also, the query param is "term" and not "word"
public interface WordsApiService {
@Headers({
"X-Mashape-Key : *insert real api key*",
"Accept: text/plain"
})
@GET("/define")
void getWordDefinition(@Query("term") String term, Callback<WordsResponse> callback);
}
Upvotes: 2