dimanche 10 novembre 2019

How setup an adapter to return data from an API for my application route in Ember data?

I'm learning to use ember data. I want to build an image searching app using Pixabay's free API.

I want to send search queries to adapter and get the results in route via model. First of all, I'm not sure how to create adapter for application route. I found many tutorials on ember data, they all built adapters and model for a specific model not on the application route.

app/routes/application.js

import Route from '@ember/routing/route';

export default Route.extend({
  model(){
    return this.store.findAll('application');
  }
});

app/models/application.js

import DS from 'ember-data';
import Model from 'ember-data/model'
const { attr } = DS;

export default Model.extend({
    largeImageURL : attr('string')
});

app/adapters/application.js

import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
    host:"https://pixabay.com/api/?key=<API-KEY>&q=<queries>",
    pathForType(){
        return '/';
    }
});



Aucun commentaire:

Enregistrer un commentaire