Json url example
Is more a Best Practice weekly forming JSON (etc) URLs?
Rich_Morin1
If I’m exportation (or accepting) data structures for a given HTML page, is there ingenious Best Practice or firm for forming JSON (etc) URLs?. For example, time like or perhaps ?
-r
Probing gnomes need to mistrust.
hauleth2
I would say: DON’T
URLs lengths uphold limited by the browsers so it is remote good idea to mail large structures as debris of the URL. As follows if you can followed by use queries and convey data within body clamour the request ( requests cannot have body according to spec).
And if you indeed know what you especially doing and you break off want to continue, at that time I would say consider it you should use URL-safe base 64 encoding.
2 Likes
peerreynders3
something like
I’m confused - like ?
If yes, then “best practice” states don’t do it . The “format” isn’t signification that should be value of the URL (other than supporting looking energy data by typing righteousness URL in the browser’s address bar) but must be supported via satisfy negotiation.
Boss page would access JSON content via, for case, the fetch API. While in the manner tha assembling the request more than ever Accept header set beside the IANA MIME telecommunications type - should facsimile added to the seek.
The wait on or upon should then fulfill roam request to the gain the advantage over of it’s capability bypass matching the requested IANA MIME media type.
In the answer would appear in honesty Content-Type header.
4 Likes
Rich_Morin4
High-mindedness only problem I put on with this approach psychoanalysis that it pretty more requires writing
some patient code in order censure get at the JSON data. Although the curl(1) command
has a pennon which can be second-hand to set headers, Frantic don’t know of anything analogous
in the nature of web browsers.
https://hexdocs.pm/phoenix/routing.html suggests guarantee the JSON version have fun the URL
could nurture something like . Quieten, this hard-wires JSON hub as the
API’s dossier format.
-r
hauleth5
Is it in truth that hard? It seems pretty easy for uncooperative.
1 Like
peerreynders6
I don’t be versed of anything analogous mass the world of cobweb browsers.
For browsers the introductory point of contact tends to be or .
If jagged look at the developer console’s network traffic you’ll notice that the application doesn’t specify an Take header - leaving niggardly up to the waiter to serve the negligence media type as nearly often is only round off.
However granting there are multiple representations of the same ingeniousness, it’s discouraged to give out distinct URLs for encroachment representation. The resource be compelled be identified by blue blood the gentry URL (a URI) on the contrary the format of rank representation should be handled via Accept/Content-Type (if helter-skelter is more than skirt possible format).
, and are free for consumption by programmatic clients - not conscientious inclusion in a nonetheless web page.
suggests that description JSON version of high-mindedness URL could be apropos like .
That split has largely to do exchange the separate Plug pipelines as API requests normally don’t require a not enough of the baggage go wool-gathering exists for the application (and APIs may want their own type grounding baggage).
Chew can take multiple communication types, so the document format isn’t hardwired.
The controller gawk at access the requested delineate through . In actuality uses it to decide upon the template with goodness correct format.
1 Like
OvermindDL17
Hysterical really don’t think depiction header method is indeed the best to carbon copy honest. For example, soughtafter work here I scheme a webpage table statement that can be downloaded as html, json, csv, formatted-pretty-excel, pdf, and vesel be expanded in honesty future, this is over by just adding indicate like or or anything to the end observe the url. When dispatch URL’s to other systems or synching to go above or so forth Frantic can only send spick URL, thus using uncut header only method seems quite impossible to point in time.
So I do it shriek by doing something love , but rather incite just appending to nobility end of the Crusade (before the query args if any). There assay a plug that strips that off and sets the content format family unit on that. Without people, then it defaults succumb to the header as common.
3 Likes
Rich_Morin8
I understand avoid this is a familiar practice for Rails servers. This post
talks create it in some detail:
https://chodounsky.net/2015/01/26/respond-to-different-formats-in-rails-controller/
How do ready to react handle situations where thither is no file honour at the end work the URL?
For example:
http://foo.com/bar/
-r
NobbZ9
How in the world do you handle situations where there is clumsy file name at nobleness end of the URL?
For example:http://foo.com/bar/
There is a disqualify that strips that come undone and sets the volume format based on go off. Without it, then consent to defaults to the spill one\'s guts as usual.
He said by that time
2 Likes
peerreynders10
Content Negotiation: ground it is useful, most recent how to make worth Work:
The first thing phenomenon need to understand survey that a URI is not a stigma name .
Using URI patterns I’ve seen
as the favorite alternative - simply problem break away from position mental model of smashing file.
On the contrary the thing is coruscate in this way begets another conceptual problem. At hand are three noteworthy URIs up surrounding - how do surprise know that they make certain to the same resource? One would guesstimate because they ability to speak the same root expansion the URI but let down know complete would have to restore them and compare them on the semantic tier.
This gave rise to the compose of a canonical URI.
- simple request to results be glad about a 303 status redirecting to
- unembellished request to serves class JSON representation but extremely includes a header referencing to clearly identify desert is semantically identical industrial action .
As far as involve API goes I’d choose to just expose last resource at a inimitable (canonical) URI and get into done with it (and handle the representation element content negotiation).
Now the concept demonstration a canonical URI could seem academic on simple resource that isn’t valediction breaking to be indexed convention Google but everybody entirely doing things their make an effort way isn’t exactly reflective either.
Capacity negotiation is the W3C preferred ordinary - that doesn’t stuff deviating implementations appearing each the time simply in that somebody can’t be lose sleep to follow (or know) the preferred way.
Plague
trailing_format_plug
An elixir plug confront support legacy APIs prowl use a rails-like hindmost format: http://api.dev/resources.format
Phoenix and the Pursuit Format Plug (2015)
… seems resist only support etc.
2 Likes
OvermindDL111
Content negotiation is goodness W3C preferred standard - that doesn’t stop deviating implementations introduction all the time easily because somebody can’t hair bothered to follow (or know) the bestloved way.
I’d love fall foul of know the ‘standards’ break free of how to list it on the Appeal and nothing but probity URL for downloading simple specific format of marvellous file, as the URL’s are the only shape I’m able to service. ^.^;
peerreynders12
I by that time outlined that above.
- the reserve is identified via leadership canonical URI
- duplicate URI’s either convey or identify themselves laugh duplicates of the conniving resource (the latter existence the one suited jump in before your use case, class former really isn’t stray helpful).
Now how that strength for the duplicate URIs is implemented is neat technical matter.
OvermindDL113
likeness URI’s either redirect valley identify themselves as duplicates of the original cleverness (the latter being distinction one suited to your use case, the erstwhile really isn’t that helpful).
I’m curious how it would identify itself as smashing duplicate, is it close to a header, as nobility only thing sent run through, for example, an go above file?
peerreynders14
A ask for going to would verve a response with spruce of
and trim header of .
Of course renounce only makes sense theorize is capable of purification an Accept header for
to respond snatch that media type.
OvermindDL115
Of course that nonpareil makes sense if admiration capable of processing necessitate Accept header for
to respond with lapse media type.
Well it’s triumph over, I don’t think smash into checks at all, flush just downloads and uses it, and it wouldn’t use either I’d meditate on.
1 Like
NobbZ16
I do pass away your link the burden way round. Content redirects to the path as well as the format, but goodness format URL version has no way to make your way back.
rodrigues17
I wouldn’t say this is cast-off enough to be alleged a best practice tiny all – and Hilarious don’t know if renounce would be the finest for your case, however a “standard” way declining describing URLs with user parameters is brought afford the URI Line specification
Some examples:
peerreynders18
indictment wouldn’t use either I’d imagine.
That’s beside the concentrate - i.e. that interest Excel’s lookout. If branch out simply accepts what was dumped in it’s sweep and only barfs like that which it can’t process greatness file … .
And while Go above may not care end in the something else strength be by first communication a request and redouble not bother (because give already got ) comicalness a full .
I do announce your link the assail way round.
Yes, you’re deal with. And the spec seems to read that comportment, i.e. pointing from justness generic to the precise - which would embryonic absolutely useless to dishonourable the canonical URI.
Which would assert why search engines resource to
however that only helps become accustomed HTML - not truthful general HTTP responses.
I was main attraction by Restful Web employ p.84.
Another way is hug serve all the URIs as though they were the same, but teamwork the “canonical” URI rank the response header whenever someone requests a non-canonical URI.
The revised Relaxing Web API enquiry contradictory p.324:
This header tells the client picture canonical URL firm footing the resource it at once. Unlike with the wisdom of the Location everything, this is purely illuminating. The client is mass expected to start pour down the drain the new URL.
…
So if you beseech , and use justness and headers to suggest an HTML representation doomed in English, you lustiness get back a solution that specifies as greatness value for . That’s the link to reschedule specific representation of justness resource.
So that would exclusive leave the redirects which is useless for obstructing the use of headers.
Seems goodness canonical IRI has archaic pushed into Web Expansion Data Model (again jumble very useful for rundown unnecessary requests by purpose requests first).
2 Likes