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.
LVL 1
Black SulfurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
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.
Black SulfurAuthor Commented:
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?
zephyr_hex (Megan)DeveloperCommented:
I only use my model for database related stuff

I'm not referring to a model method.  I'm referring to model properties.  Your model should have properties, and I would add a property for the api url.

class MyModel
{
     public string Url { get; set;}

     public MyModel()
     {
           Url = "blahblahblah";
      }
}

Open in new window


Then, whenever you instantiate an instance of your model, it will have the api url.

var model = new MyModel();
var url = model.Url;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.