Link to home
Start Free TrialLog in
Avatar of Crazy Horse
Crazy HorseFlag for South Africa

asked on

where to put api in mvc structure and how to call it

I want to use an API in my mvc project but am not sure where to put it or how to access it.

My current structure in the root has 2 folders with subfolders like:

App
  config
  controllers
  libraries
  views
  models

public
  css
  js
  img

The API has a root folder and api folder inside:

SomeAPI
  api

So, where would the correct place be to put the SomeAPI folder in relation to my structure and how can I call it?

The api documentation say I am meant to do this:

data-api="/SomeAPI/api/"

Open in new window


but this assumes that I am putting the SomeAPI in my root directory, not using MVC.

Any help would be much appreciated. I have tried all different directories but nothing works.
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

I would create a model class for the api, with one of the properties being the api url.  Then, your methods that relate to the api would be inside the class, and you would instantiate an instance of the api from the controller, and call your methods, etc from there.
Avatar of Crazy Horse

ASKER

Hmm. I am a bit confused now. I only use my model for database related stuff and this has nothing to do with a database. Could I put it in my controller? It is an API that gets instagram images and displays them in a grid.

So, in a non-MVC world, you would just put this wherever you want it to show up:

  <div data-il 
     data-il-api="/someAPI/api/"
     data-il-username="myInstagramAccount"
     data-il-hashtag=""
     data-il-lang="en"
     data-il-show-heading="true"
     data-il-scroll="true"
     data-il-width="270px"
     data-il-height="350px"
     data-il-image-size="medium"
     data-il-bg-color="#285989"
     data-il-content-bg-color="#F8F8F8"
     data-il-font-color="#FFFFFF"
     data-il-ban="">
</div>

Open in new window


And where in the folder structure would I put the folder for the API?
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial