Send POST request from ember to specified URL - django

I am new to full stack development, and having an issue with a web application I'm working on for my employer. I was tasked with creating a fairly simple application that we can scale over time. For now all that it needs to do is take data from one of our databases, and pass it to a front end application. Using this front-end app our workers should be able to double check the information passed in, and make sure it has been properly translated to a new format. After it is translated I want to send an HTTP POST request to our new systems back-end and have it add this new data via the REST API. Essentially it's an application that was used for practice to get me more acquainted with full stack development while making an effective tool to transfer mass data from one system to another. I can't seem to figure out how to set up something in ember.js to send that POST request to somewhere other than my back-end though.

I believe after re-reading the page on the ember.js site I found my answer. Sorry for posting a question that was already answered elsewhere. It was asked after a while of googling and not finding what sounded right. Just needed a day to let my brain reset I guess. In any case, if somebody else stumbles upon this post and (like me) wasn't comprehending at the time, the answer lies here: https://guides.emberjs.com/v1.10.0/models/connecting-to-an-http-server/
You simply create a new adapter with the host you want to send requests to. Then you can create a new model in my case to serialize the data in a way the host will understand what you're trying to transfer to it. This will allow for data migration between sources like I desired. Sorry again for the unnecessary post, but hopefully it helps someone else in the future.

Related

Is there a way to unlock all http methods without changing the war file?

I have a .war file deployed in Jetty (I didn't build it, and it's not possible to create a new instance).
An OPTIONS request to http://example.com/rest/object/{uuid}responds with HEAD, DELETE, GET, OPTIONS. The people that built the war claim that it's not an issue with their file.
Is there a Jetty config file I can change to allow all the http methods?
If this is something I have to do in a Jetty Java file, I am a Jetty noob, so please be verbose, or point me to some docs that I can read.
Note: I can POST via CURL, but not via http...
Edit: (I was posting to a different Endpoint with CURL)
This is not an answer to the question I posted, but it allowed me to understand what was happening, which lead to the question being irrelevant for my particular issue. With that being said, I won't mark this as the answer in the event it is answerable (which I don't think it is, you'll see why in a minute).
The short answer is I was trying to POST to an endpoint that expects the object to already exist:
http://example.com/rest/object/{uuid}
What I should have done was use an endpoint, where if you POST, it understands you want to create a new object:
http://example.com/rest/object
The longer answer
Let's say you have a REST Endpoint that allows you to get a specific object, like this:
http://example.com/rest/object/{uuid}
Since you're dealing with a specific object, you typically wouldn't want to POST a new object there. POST means 'create a new object'. If you were able to POST there, you'd essentially be overwriting that Object... and that's what PUT is for, but it's debatable. Also, PUT wasn't an option either...
So, because of its subjective nature, some Web Services limit request methods so you must do it the way the architects intended. The REST Server I am running doesn't have much in the way of documentation, so I was unaware of these restrictions, and am still puzzled by it.
What I thought I was doing was saying "OK, I want to create an object with this id. So if I POST my data to that specific UUID, the server will know I want to create a new object." What I should have been saying is "OK, I want to create a new object. It's UUID is already defined in the data, so all I need to do is send it to the endpoint that handles those objects, and expects a POST." Like this:
http://example.com/rest/object

Django / Twisted (or hendrix) help to start

I'm involve in a new proyect, let explain it briefly.
We have an application server, this server can be interfaces with other systems using udp (this is a design policy, I can change it).
Now we need a web app to collect the information sended by the application servers to show some reports and send back some configuration when we need.
We are very interested in Django with Twisted (or Hendrix), we are very new in python world, I surf in Internet for days and so far I undersand some concepts but I mess about how to start with a proof of concept, so I'm here.
I need an example or guide about how to start, our idea is simple for this proof of concept.
An Application server send some data over udp.
A twisted/django app receive that info and save it in a database table.
A django web page read the database table and show a report. I don't know if the web page need to run on twisted or not.
Please, I read a lot of post for days and I'm lost about how to start.
Thank you a lot in advance.
Best Regards.
Learn each part of your stack one-by-one. Start by following a Django tutorial, then once you're comfortable with Django run the app using Hendrix instead of Django's manage.py, finally add your UDP tasks via Twisted from Hendrix. Lucky for you all the projects you've mentioned have good communities and documentation. You don't have to get everything working perfectly, just get some working pieces.
Write some code, then when you have some running code and you get stuck somewhere, hop back onto Stackoverflow and ask your specific questions.
Update
As it so happens, there's a video which shows how to integrate Django + Hendrix. Give it a shot and tell us how it goes.

Hande Series of Web Requests in a specific way

I am sorry in advance; I am just learning Web development and my knowledge of it is quite limited.
I will describe my problem first.
I have relatively large amount of data (1.8-2 GB), which should be hidden from a public web access. However, a user should be able to request via url call a specific small subset of data and see it on his / her webpage.
Ideally, I would like to write a program on a web server. Let's call it ./oracle, which stores the large amount of data in primary memory.
Each web user should be able to make a specific string calls to oracle and see oracle'sresponse on a web page as html elements.
There should only one instance of oracle, and web users should make asynchronous calls to it.
Can I accomplish the above task with FastCGI or any other protocols?
If yes could you please explain which tools / protocols should I use / learn?
I would recommend setting up an Apache server because it's very common and you'll be able to find a lot of answers to any specific questions here on StackOverflow already.
You could also look into things like http://Swagger.io which can help you generate your API.
Unfortunately, everything past this really depends on what you use to set up your server. Big picture though:
You'll need to open up a port to listen to incoming requests
You'll need to have requests include the parameters they want to send to oracle
You could accomplish this the URI, like localhost/oracle-request?PARAMETER="foo"
You could alternatively use JSON in the body of the http request
Again, this largely depends on how you set up step 1
You'll need to route those requests to the oracle
This implementation depends entirely on step 1
You'll need to capture the output from the oracle and return it to the user
Once you decide on how you want to set up your server, feel free to edit your question and we may be able to provide more specific help.

How does Syndication work in Django?

Why this (hopefully) isn't a broad question:
I've been looking at the Django source code on syndication. I understand functionally what these feeds are and what they do but I'm not sure how the magic happens.
Actual question:
What is Django doing under the hood to send these changes out across the wire? Is Django just creating an object (like an XML file) the Client reads and not even using the network? What mechanism is employed to ensure users get those updates in a 'reasonable' amount of time - is it a combination of the browser (or some other software) knowing to go look for updates while Django diligently adds data to a file, or does Django do most of the work?
There's no magic, and Django does not do anything to even try to ensure clients get updates in any particular amount of time.
Feeds, like almost everything on the web, are an entirely pull-based mechanism. Feed readers are responsible for periodically requesting updates from the client.

How to create an API and then dynamically retrieve data from and add new data to it?

To start off, I am extremely sorry if my question is not clear but I have very little knowledge about web services in general and the vast nature of varying available information has driven me crazy over the past few weeks. So please do bear with me.
Summary: I want to create a live score update app for android. (I haven't added android as a tag because I do know how to retrieve data from say twitter's JSON api.) However, like the twitter JSON api, I want to be able to add(POST maybe?) data to the Apache 7.0 service that I have running. I then want the app to be able to be able to retrieve this data that I have posted.
I had asked a more generic question earlier and I was told that I should look up some api's. I did that but I have still not been unable to make a break through.
So my questions is:
Is setting up an API on my local web service the correct way to do this?
If so, how can I setup an API that will return JSON objects to the Android app. Also, I would need to be able to constantly update this API with new data.
Additionally, would I also need to setup a database for all this?
Any links to well explained matter would be appreciated too.
Note: I would like to carry this out using a RESTful Web Service through Jersey and use JSON Objects during retrieval.
Again, I am sorry about my terrible knowledge with web services in general despite trying my best to research a lot. The best I could do was get my RESTful Web to respond to a GET with some pre-defined text that I had set in Eclipse.
Thanks.
If I understand you correctly, what you try to do is something like this:
There will be a match or multiple matches of some sort. Whenever a team/player scores someone (i.e. you) will use the app to update the score. People who previously subscribed to the match, will be notified and see the updated score.
Even though I'm not familiar with backends based on Java, the implementation should be fairly similar to other programming languages.
First of all a few words to REST in general. REST is generally needed, when you need to share information between multiple devices and or users. This seems to be the case here. To implement the REST you are going to need an API of some sorts. Within the web APIs are implemented by webservers answering to certain predefined HTTP Requests.
Thus setting up an API on a web server is the correct way.
Next a few words on databases. A database is generally needed, if you want to store information persistently. This might, or might not be what you are planning to do. If there are just going to be a few matches at the same time and you don't care about persistence of the data, you can use Java to store a collection of match objects in memory. I'm just saying it is possible, not that it is a good idea. Once your server crashes or you run out of memory due to w/e reason, data is going to be lost. (Of course within the actual implementation you want to cache data for current matches in some way and keeping objects in memory is way to do so).
I'd recommend to use a database.
Within the database, you can then store and access information about the matches like the score, which users subscribed, who played, etc.
JSON is just a way to represent the data/objects that will be shared between the server and the client. You can use JSON to encode request and response data/bodies.
The user has to be informed about the updated score. There are two basic ways to do so. Push or Pull. With pull, the client will check for updated scores after fixed intervals or actions. With push, the server will notify the client about changed scores which will cause him to update the information. Since you are planning on doing a live application and using Java anyways, push seems to be the better way to go.
Last but not least let's have a look at a possible implementation using
Webserver (API endpoints + database)
Administrator (keeps score updated)
User (receives updates)
We assume that the server will respond to HTTP Requests (POST#/api/my-endpoint) with JSON-Objects.
Possible flow
1)
First the administrator creates a match
REQUEST
POST # /api/matches
body: team1=someteam&team2=someotherteam
The server now will create a match object and store it in the database. The response will contain information about the object and whether the action was successful.
2)
The user asks for a list of matches
REQUEST
GET # /api/matches/curret
The response will be a JSON object containing a list of current matches.
RESPONSE
{
matches: [
{id: 1, teams:...}, ...
]
}
3)
(If push)
A user subscribes to a match
REQUEST
GET # /api/SOME_MATCH_ID/observe
The user will now be added as an observer for the match. Again, the response contains information about whether the action was successful or not.
4)
The administrator updates a score
REQUEST
UPDATE # /api/SOME_MATCH_ID
body: team1scored...
The score now gets update on the server (in memory/database) and the user will be notified about the updated score.
5)
The user gets the updated score
REQUEST
GET # /api/SOME_MATCH_ID
RESPONSE
... (Updated score in some way)