I have this data management panel of IP addresses, which belong to organization and have users responsible for it.
Now I have the route /api/ip and /api/ip/{id} to get all or specific IP. The format of one resource is:
{
"ip": "200.0.0.0",
"mask": 32,
"broadcast": "200.0.0.1"
}
Now when I choose the IP, I want to show IP information, also the organization information it belongs to and the users, that are responsible for it, information in one page.
Is it good idea to return the following data format, while requiring /api/ip/{id}:
{
"ip": "200.0.0.0",
"mask": 32,
"broadcast": "200.0.0.1",
"organization": { /* organization data */ },
"users": { /* users information */ }
}
This way I get all the information I need in one request, but is it still RESTful API?
Or should I make 2 more api routes like /api/ip/{id}/organization and /api/ip/{id}/users
and get all the data I need in 3 separate requests?
If not, what would be the appropriate way of doing this?
I would do the last one, using Hateoas, which allows you to link between the resources. There is a really great bundle for that called the BazingaHateoasBundle. The result will then be something like:
/api/ip/127.0.0.1
{
"ip": "200.0.0.0",
"mask": 32,
"broadcast": "200.0.0.1",
"_links": {
"organization": "/api/ip/127.0.0.1/organization",
"users": "/api/ip/127.0.0.1/users"
}
}
It is perfectly okay to have nested resources. You can expand them the way you showed, or you can collapse them by adding links (with the proper link relation or RDF metadata). I suggest you to use a standard or at least documented hypermedia type, e.g. JSON-LD + Hydra, or HAL+JSON.
Related
I am working on travel portal. In this listing api I'm getting Flight_Key and Search_Key.
so for the next api call I need flight_key and search_key. But I want to know which is best way for pass this two key listing page checkout page. I can not pass in url because key length is very big.
Which method or logic I do I have to use to pass variables from the listing page to the checkout page?
I am developing this in CodeIgniter 3.0 in PHP.
Sample for Flight Key and Search Key
"Search_Key": "W0KzomlraSkwtgLSE+RI6Tzkkm3zLj+TDvLtvlf7KJx0cOGxLo3r7bf61ycck38odvn8z24Gc50+Uzwqs2blEo0OveFU1xrWeMftXBXB2r3/Mlt3cW8Nr/JKNUsAJFQmtcnJ2wFBzGiUyeE0YvnZ8mJlnuyuIxLuSxmPN0g2qtFbgo0igTNZqhigzGfH+P0luTg/gRjfWS3+JafR8xaPMoXdaQenac/+A7KMFuOkJDBOi5As1gWjd/aH6X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Q3+0ZFWEEaukIoivZ29Mg1nwVIgRxvCfVRdg2Ba5x0jY7zTdoJXaWMqSHnGJUqrx59N9Y9EE534oUNgLQy7lHxcRkGOMMDGaeFVgeD3QUjD3g+uvtc9cgEDitUc4UQtVMNWaUBn/tTq18VAS8JbVWNZlFrTHDfRd1rCp6zmikvO/aqfKprB4rswISEFLzvmiLT2SQYfvDdLzC9LznpEvj/akBbvz2yZ+dyO7uUlxILlfCgV6aeBIMa14v6hkAaeEWIWzrem2PmQFmJL04iBa6rEhcCE6wxMxkxoujp0POk+Xsb/d4uaKj0Pjxj1eAHtp0RkarCc+6aDOcfZ4Hkjkexe6FsdomKIPalR+Vuab/GTDIWGYVlM/br7fAC8uElh01Z2HMA==",
I am calling third party API for listing. Every flight has a different flight_key and search key is common. Please provide example for more clarification.
Sample response
{
"Response_Header": {
"Error_Code": "0000",
"Error_Desc": "SUCCESS",
"Error_InnerException": "",
"Request_Id": "5500887959052",
"Status_Id": "11"
},
"Search_Key": "yRb9JOxw6JYeSN7HNN3ynvs8jIMLwTRgW1FI3E9asza6C85fPfWRuVeR9qLBlCnwlJEZDQvTE5UBbctSWVGAgadY8Ocje+Z5F44DFLtFoUBMW5urVTIAWdEshPWRSRIg12URy1rEb/aqNqQSFVlvdgiQRWK+Mw/ej/38y7nMTUQWZq0SQyu5eOG2Lc2CvdYHrfBIG82FVGuYu0zp9HXTPDCXmfI4aJsFTLIBK6hCy5BVIYSqaZdzcGU/InBI16m4KXw/HBDTE4SjZhzM+e1yMgJgdhQel8QiAw/G/IgR3QjQ50g5nILAXPmS2Q4BGhTEigWWrab1Dr+5vE6LtXinVj1/X1ACQ7EGIWqI646L5VNwEJPBWwL2R51/XFznEjZlGqFwCd9nXh4w7hiKt+Q+KTs3JbZO0ZcfGdVdQuyYruQCSKpLc/QoJ0FFXNgHv3kIgeV05qe+jpN9Elbo16zhvhPlPIer+tRNFJ/NiU6G+4nLLqKelEYczJOZGKRHWDNWiaZt7GrlCc87ckk7j1RiU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Key": "KEYiPgFisf+PPT6e4pEIgRnvTxZlqgFY5f+x6sEGETJ6jYjD0WJIKQdp8q8jmuqPHC3KBkq5gLxH1xU3YrxWojQ3E5XjkWtGGMTxO8ttjglkH1xkrPhkr0nAsfo3iN0F+cWQcaS+iQjV3zhmb/nyqBJnrUOyLN1WLMQuz8O9AdE0104GAotZJI+3BIypAbOkAUjwEtgWV2X6qG/G94+Jzu8EuiDv6wefCCE3ApVcvQKGjwxT4rdnmHKG1PHO9VVjkHByRzwyonKBBRq1v91G1OBqlUCftdRx/xxhArJjtU3O5tw1XbOyhWC+25zMu4UcXh2e+ApMXizUmE6QTc/BZp9vNIpdWqMrOZvXsLXE9O8TkSIvO/bpKdNCQhnr2aK1KXgVjuWrYlSHTYd13CJ0P73wN5435I2MB8Vz+xUl+p1Hs9Bsr3VxiGTbxxpodkYyoqoq1dSNbP4E3nrroUz1rmSHEkLWBglPOkS96UxB7lDxosTmrOyC4g+4UZGnlKzpOBtA5sa7mVdGIL4LtvyV0HeyozHbFhUy9YQf+g7i7B/Xd9a1wz4zr1vQK5SHtRJ8ft6aJX4yXw2LwFUyLzITWr17YG2zGCzv9RflnwYLn4vG58yA9T8agxAXEW2dOTVCG0mNae9J2me3VU6nay65sQ6nvfjFHR5seipQD5CuWJ+7HjmlboeOa7bI/8C8TD78u8lhDvb4oauYKyZ7nmki9mRAOm/Y1w4FMvJZujFGXXEjSgrV0Sd434ZcPeQvadFdfDP",
"TravelDate": "09/25/2022"
},
]
}
If we have a link to another OneNote page in the HTML content:
<a href="onenote:SectionB.one#Note1§ion-id={<section-id>}&page-id={<page-id>}&end&base-path=https://<path>"
... before I write a parsing routine to extract that link, I thought I'd ask if I'd overlooked anything in the OneNote API to make this easier.
===========================================================================
[EDIT] Well, I've written my routine to extract the page-id of the linked note, but that page-id turns out to be quite different from the page-id that's returned as a property (id) of the linked note itself - and it doesn't work :(
Here's an example:
(1) page-id extracted from link: A8CECE6F-6AD8-4680-9773-6C01E96C91D0
(2) page-id as property of note:
0-5f49903893f048d0a3b1893ef004411f!1-240BD74C83900C17!124435
Vastly different, as you see. Accessing the page content via:
../pages/{page-id}/content
... for (1) returns nothing
... for (2) returns the full page content.
(The section-ids returned by both methods are also entirely different.)
So, how can I extract from the link a page-id that works?
Unfortunately, the OneNote API currently does not support identifying links to other OneNote pages in page content. Links in OneNote can be links to anything: websites, other OneNote pages/sections/notebooks, network shares...
The API does support getting links to pages by using
GET ~/pages
GET ~/sections/id/pages
The page metadata model contains a links object with the clientUrl and the webUrl.
Editing after your question update:
You're right - the id in the link does not correspond to the id of the OneNote API. You can however compare the id in the link with the id in the OneNoteClientUrl exposed in the API. Here's an example of the response of a
GET ~/sections/id/pages
GET ~/pages
{
"title": "Created from WAC",
"createdByAppId": "",
"links": {
"oneNoteClientUrl": {
"href": "onenote:https://d.docs.live.net/29056cf89bb2d216/Documents/TestingNotification/Harrie%27s%20Section.one#Created%20from%20WAC§ion-id=49b630fa-26cd-43fa-9c45-5c62d547ee3d&page-id=a60de930-0b03-4527-bf54-09f3b61d8838&end"
},
"oneNoteWebUrl": {
"href": "https://onedrive.live.com/redir.aspx?cid=29056cf89bb2d216&page=edit&resid=29056CF89BB2D216!156&parId=29056CF89BB2D216!105&wd=target%28Harrie%27s%20Section.one%7C49b630fa-26cd-43fa-9c45-5c62d547ee3d%2FCreated%20from%20WAC%7Ca60de930-0b03-4527-bf54-09f3b61d8838%2F%29"
}
},
"contentUrl": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162/content",
"thumbnailUrl": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162/thumbnail",
"lastModifiedTime": "2016-03-28T21:36:22Z",
"id": "0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162",
"self": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162",
"createdTime": "2016-03-24T20:38:16Z",
"parentSection#odata.context": "https://www.onenote.com/api/v1.0/$metadata#me/notes/pages('0-a50842a9873945379f3d891a7420aa39%2114-29056CF89BB2D216%21162')/parentSection(id,name,self)/$entity",
"parentSection": {
"id": "0-29056CF89BB2D216!162",
"name": "Harrie's Section",
"self": "https://www.onenote.com/api/v1.0/me/notes/sections/0-29056CF89BB2D216!162"
}
}
You can also filter server side (if you want to save yourself from paging and regex's ;) ) for id's in the links by using:
GET ~/pages?$filter=contains(links/oneNoteClientUrl/href,'a60de930-0b03-4527-bf54-09f3b61d8838')
I'm currently trying to find all the pages where images/media from a particular category are being used on Wikimedia Commons.
Using the API, I can list all the images with no problem, but I'm struggling to make the query add in all the pages where the items are used.
Here is an example category with only two media images
https://commons.wikimedia.org/wiki/Category:Automobiles
Here is the API call I am using
https://commons.wikimedia.org/w/api.php?action=query&prop=images&format=json&generator=categorymembers&gcmtitle=Category%3AAutomobiles&gcmprop=title&gcmnamespace=6&gcmlimit=200&gcmsort=sortkey
The long term aim is to find all the pages the images from our collections appear on and then get all the tags from those pages about the images. We can then use this to enhance our archive of information about those images and hopefully used linked data to find relevant images we may not know about from DBpedia.
I might have to do two queries, first get the images then request info about each page, but I was hoping to do it all in one call.
Assuming that you don't need to recurse into subcategories, you can just use a prop=globalusage query with generator=categorymembers, e.g. like this:
https://commons.wikimedia.org/w/api.php?action=query&prop=globalusage&generator=categorymembers&gcmtitle=Category:Images_from_the_German_Federal_Archive&gcmtype=file&gcmlimit=200&continue=
The output, in JSON format, will looks something like this:
// ...snip...
"6197351": {
"pageid": 6197351,
"ns": 6,
"title": "File:-Bundesarchiv Bild 183-1987-1225-004, Schwerin, Thronsaal-demo.jpg",
"globalusage": [
{
"title": "Wikipedia:Fotowerkstatt/Archiv/2009/M\u00e4rz",
"wiki": "de.wikipedia.org",
"url": "https://de.wikipedia.org/wiki/Wikipedia:Fotowerkstatt/Archiv/2009/M%C3%A4rz"
}
]
},
"6428927": {
"pageid": 6428927,
"ns": 6,
"title": "File:-Fernsehstudio-Journalistengespraech-crop.jpg",
"globalusage": [
{
"title": "Kurt_von_Gleichen-Ru\u00dfwurm",
"wiki": "de.wikipedia.org",
"url": "https://de.wikipedia.org/wiki/Kurt_von_Gleichen-Ru%C3%9Fwurm"
},
{
"title": "Wikipedia:Fotowerkstatt/Archiv/2009/April",
"wiki": "de.wikipedia.org",
"url": "https://de.wikipedia.org/wiki/Wikipedia:Fotowerkstatt/Archiv/2009/April"
}
]
},
// ...snip...
Note that you will very likely have to deal with query continuations, since there may easily be more results than MediaWiki will return in a single request. See the linked page for more information on handling those (or just use an MW API client that handles them for you).
I don't understand your use case ("our collections"?) so I don't know why you want to use the API directly, but if you want to recurse in categories you're going to do a lot of wheel reinvention.
Most people use the tools made by Magnus Manske, creator of MediaWiki: in this case it's GLAMourous. Example with 3 levels of recursion (finds 186k images, 114k usages): https://tools.wmflabs.org/glamtools/glamorous.php?doit=1&category=Automobiles&use_globalusage=1&depth=3
Results can also be downloaded in XML format, so it's machine-readable.
I am experimenting actually a little bit with couchbase server.
I have tried to read a mysql database table, build a document from each data row and then inserting the document with an id which I generate with
uniqid('table_name');
via cUrl, method is POST.
This so far works pretty good, until the script has inserted roundabout 7050 documents. Then an exception is thrown -> "No buffer space".
Until now I was not able to fix this, so I decided to collect i.e. 50 rows of data build a json_encode(d) string and POST it again via cUrl.
This worked so far if I don't set the id - but I can't figure out how to set the id of the inserted documents.
Actually I try to send my documents in a format like this:
{"docs": {
"_id": {
"geodata_de_54476f7e6adc57.14196038": {
"table": "geodata_de",
"country": "DE",
"postal_code": "01945",
"place_name": "Lindenau",
"state_name": "Brandenburg",
"state_code": "BB",
"province_name": "",
"province_code": "00",
"community_name": "Oberspreewald-Lausitz",
"community_code": "12066",
"lat": "51.4",
"lng": "13.7333",
"Xco": "3861.1",
"Yco": "943.614",
"Zco": "4979.07"
}
}, ...
}
}
but this just inserts ONE document with the above object.
Maybe there is someone here who can point me the right direction.
I would use the Couchbase PHP SDK to insert these documents instead of using curl. http://docs.couchbase.com/developer/php-2.0/storing.html
Also for CB, you do not have to set the ID in the document itself. it depends. I might take a look at instead using the ID you have in your example ("geodata_de_54476f7e6adc57.14196038") and put it as the key for the object in Couchbase. Then you do not necessarily need the _id. The key in Couchbase can be up to 250 bytes of data and you can make it meaningful to your application so you can do lookup by key extremely fast.
Another option is, if you wrote your docs to the filesystem, you could also use cbdocloader utility which is specifically for bulk loading docs. If you are on linux it is in /opt/couchbase/bin/tools/cbdocloader.
Would there be a way to do a zip code lookup based on City/State input in a form? I'm thinking the Google geocode API might be the right direction. Any thoughts? I have a site built on Wordpress so the code would have to utilize PHP. Thanks in advance.
YQL can do things like this:
select name from geo.places.children where parent_woeid in (select woeid from geo.places where text="sunnyvale, usa" limit 1) AND placetype = 11
returns:
{
"query": {
"count": 6,
"created": "2011-03-16T06:49:09Z",
"lang": "en-US",
"results": {
"place": [
{
"name": "94086"
},
{
"name": "94087"
},
{
"name": "94088"
},
{
"name": "94089"
},
{
"name": "94090"
},
{
"name": "94085"
}
]
}
}
}
YQL Console
There are examples on there on how to implement queries like this in both PHP and Javascript on their site.
Geocoding is where you find the coordinates of an address. Yes you could geocode a city,state but this would give you he center of the city (as defined by the geocoder's internal database - typically a centroid or 'city hall'.
Most cities have multiple zip codes: Do you want all of these?
Similarly a zip code could contain multiple cities - especially in rural areas where zip codes can be large and cities are what other countries would call 'villages' and 'hamlets'
So you best bet is probably to get a database. There might be some free ones around (Geonames comes to mind but I don't think it has zip codes), but you might end up having to buy one.
First a note on the Google API: be aware of Google's TOS so you don't take a wasted path as others have done (sometimes unknowingly). Specifically: "Note: the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.".
Your best bet is to get a free zip code database if your project is not mission-critical; otherwise, you'll probably need a good commercial-grade database. Just google "commercial grade zip code database".
Also, see a good stack-overflow thread about this topic.