Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Implementation #3

Open
thatnerdjosh opened this issue Mar 20, 2015 · 15 comments
Open

API Implementation #3

thatnerdjosh opened this issue Mar 20, 2015 · 15 comments

Comments

@thatnerdjosh
Copy link
Contributor

No description provided.

@thatnerdjosh
Copy link
Contributor Author

Implemented API to pull images with EXIF data using the code that was presented in the meeting with a few minor changes

@cgoodale
Copy link
Contributor

Hey @NerdsvilleCEO can you please provide the latest API spec you envision publishing?

I would assume for this initial release I would be talking to http://localhost/ so what are the URLs I should look into consuming from your Flask App?

Today I hope to send over a starting collection of html, css and js to lay the foundation for the mapping page.

Thanks!

@thatnerdjosh
Copy link
Contributor Author

@cgoodale I will prepare this in a bit and get it to you as soon as possible.

@thatnerdjosh
Copy link
Contributor Author

@cgoodale http://localhost:5000/api/v1/images/ will accept GET and POST, I can just spit out the information in the DB with a GET and the image with a POST including image name as param image="image_name.jpg", is that how you would like it to work?

For example

Request:
GET /api/v1/images

Response:
{"images":[{resultset1},{resultset2}]}

Request:
POST /api/v1/images

Params for request:
image="image_name.jpg"

Response:
{"image": "url_for_image"}

@cgoodale
Copy link
Contributor

@NerdsvilleCEO that sounds like it will work. I will play around with the response and see if there is any other information I might want to fetch. Thanks!

@thatnerdjosh
Copy link
Contributor Author

@cgoodale On second thought, do we need the POST? If we have the image name, we can store it in JS, and we will know the path since we are saying the images. Maybe there is something I am forgetting about, it can be easily implemented but if it's not needed, I will just do the GET. I was reading my comment last night and realized how redundant it was

@cgoodale
Copy link
Contributor

So we begin the classic debate over API design. I hope that others in the group follow along and see how we debate this. This is a small scale example so we can make several trades and shortcuts, but I think it would be great to highlight the pros & cons of different approaches.

Scenario 1:

I like to have a single call to the server that I can use to startup my application. For this mapping application (given the small dataset) I would run a GET against some endpoint and have just enough metadata come back so I can render my page to the users so they can request more details. In our situation I would only need Longitude, Latitude, and some unique ID that I can use to request details about the object later on.

Given the data I have in the browser I would drop some markers on the map and when the user clicks the marker they care about I would then fetch the details about that record including all exif data, link to the raw image, etc.

Pros:

  • Small initial payload means fast startup and rendering.
  • User is getting only the data they are interested in by clicking on the markers.

Cons:

  • Chatty API where we are making 1 request to startup, then 1 request for each time the user wants more info. Instead we could ship all the data in 1 request and let the client work on everything without talking to the server.

Considerations:

  • To make this effectively scale to the globe the initial startup request should also take in some Geographic boundary information. That way if someone is interested in California they aren't stuck waiting for data about Europe to be loaded before they can take action. The map would also need to fetch more data as the map is moved around after starting up.

@thatnerdjosh
Copy link
Contributor Author

Ah, I see, was not considering larger scale, but that does make sense and would be better practice in my opinion, (keeping in mind I am a novice to API's) the network latency issue for a larger scale app would be the only potential issue with this approach, but since we are running on localhost and it is a demonstration there isn't an issue, so this is the plan, with a:

GET request

I will go ahead and spit out primary ID, long and lat for you to plot on the map,

POST request
Onclick of the image, we can send the primary key and I can send any additional data needed at that point, (right now I think it would just be the image, date retrieved, date taken, width and height)

Does that makes sense? Let me know if this design would work, if so I will get started on designing it in this manner

Thanks!

@cgoodale
Copy link
Contributor

@NerdsvilleCEO I think we are in agreement on this. I realize we could send all data in one simple GET request, but that means we would only have one end point to discuss and demo for the project.

Two isn't a ton of endpoints but we can talk about using GET vs. POST and talk about some of the decisions and trade-offs when designing APIs.

I am looking forward to seeing how the service will behave and getting some data on the map soon.

Thanks!

@thatnerdjosh
Copy link
Contributor Author

Finally had a little time to breath with all the work I have been needing to do, the GET endpoint has been completed and I made a pull request.

Thanks!

@cgoodale
Copy link
Contributor

Hey @NerdsvilleCEO please grab the latest code and give it a whirl on your machine. Once you start up the flask app, just open the index.html and you should see a map with some points (assuming you have some points in your local db already).

Let me know if you find any issues.

Cheers!

@thatnerdjosh
Copy link
Contributor Author

Doing that right now

@thatnerdjosh
Copy link
Contributor Author

It totally works! :) That is awesome

@thatnerdjosh
Copy link
Contributor Author

Slight bug, it makes a POST even when you click off the marker

@thatnerdjosh
Copy link
Contributor Author

Looking back 6 years later, this implementation has some major issues.

I'll try and fix some of them today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants