PokeAPI: Is there a way to request normalized data instead of nested json? - pokeapi

I've been using the PokeAPI for testing different UI libraries, and there are cases where the heavily nested JSON it returns is kind of annoying. Is there any way to get an endpoint to return canonical resource urls instead of eagerly loaded entity data? I scoured the API docs and can't find any answers.

Related

FOSElastica + FosRest + Doctrine + REST Api

Versions
Symfony 2.8.2
FosElastica 3.1.8
FosRest 1.7.7
Doctrine 2.5.4
Problem
Hello,
I have some MYSQL's tables with many relations. I would like a build a REST Api, in HTMl a JSON, to get them.
It is working in HTML, but doesn't in JSON.
Indeed, in JSON I am returning array with multi dimensional, and doctrine made each request to get data.
This maneuver makes many times and fail.
The solution will be to make a SQL join with the return of ElasticSearch but I don't how to make that.
Any idea?
The better solution is to make a REST API.
REST API never reterning a deep JSON Object, but only the asked object.
For instance one Entity People containing a list of Cars.
You have to make routing something like that :
Returning all users as light object (only id ans very important informations) :
/users
Returning one Full User WITHOUT his cars :
/users/{userId}
Returning full list if cars (as light objects) :
/users/{userId}/cars
Returning full car object (without sub object obviously) :
/users/{userId}/cars/{carId}
After you can manage your routing as you want with RESTFull

JSON-LD additional properties, that are not in the dictionary schema.org

Plan to refactor the data JSON format to JSON-LD, using a dictionary schema.org.
The problem is that we need to pass additional properties that are not in the dictionary schema.org, we cannot abandon these properties because there it is technical metadata that is used in the logic of our AJAX sites.
The question of having the properties are not in the dictionary schema.org, create problems for indexing AJAX our site, or search bot will simply ignore the properties he does not know and it does not affect indexing?
Bots will simply ignore those properties. If you don't map them to URLs (for example by setting them explicitly to null in the context), they are effectively invisible for a JSON-LD processor. See http://www.w3.org/TR/json-ld/#advanced-context-usage for more details

CakePHP custom data source "READ" return structure

I'm in the process of developing a custom datasource to interface with a REST API. In the example provided on the CakePHP website they return the data from a READ operation in this structure:
Array(
'ModelName'=>Array(all the actual data here)
)
The code looks like:
return array($model->alias => $results);
Is there any specific reason to return the results this way or can I just return as:
return $results;
My concern is that if I don't return in the CakePHP specific format I might not be able to use some other built in functionality. I don't see anything specific about the need for this structure. Any insight would be appreciated.
It comes down to CakePHP's data structure guidelines. The reason Cake uses the model name as the array key and the results as the value is because it makes it very easy to read when you have multiple tables returned in the same query - after all, Cake models are relational database maps and are built to be associative.
How you use the results from Cake's data results is up to you. Yes, there are times when the model name prefix annoys me and I find it useless, but most of the time it can be very useful to help you distinguish between multiple associated table results in one query.
If you don't think you'll ever need this and don't mind breaking Cake's data structure conventions, there's nothing wrong with breaking away from it - but if I were you I would create your API interface in a way where it conforms exactly to the structure that their built in datasources return (for current and future compatibility reasons mainly).
More info on creating a REST API datasource is here in the manual.

Push Client-Metadata to Server

we have a very dynamic metamodel which changes frequently. We don't use EF but an own Database-Technology.
As we didn't find any good documentation on how the server-side metamodel has to be created "by hand", we decided to create the client-side metamodel and import this one into breeze when loading the application.
Now we have the problem, that eventhough we tell breeze to get all Person-Objects and take 3, the server expands all associations and returns more than 3 results. Breeze then cuts the result on the client to 3 and fills the properties.
Now I'm wondering, if we just didn't understand some of the concepts. All we want to do is to tell breeze dynamically how our metamodel looks like without using EF or NHybernate. Is there any documentation on that?
The only documentation on a Schema I found was this one:
http://www.breezejs.com/documentation/metadata-schema
But it only explains the client-Side-Metamodel but not the Schema that our Server-Side would have to generate. As far as I see it, the Server-Side-Metamodel gets translated into the client-Side-Metamodel anyways.
Would be nice if someone could clarify or provide a link with all the "basic information" about the topic.
The client metadata is for the Breeze client. The server shouldn't need it, because it already knows what the domain model looks like. The content of server-side metadata typically comes from the database and/or the mapping layer, when using an ORM.
Breeze's server-side WebApi filters attempt to apply the OData query parameters to the IQueryable that comes from the data provider (EF, NH, or whatever). If the data provider's LINQ implementation is incomplete, that could cause the problem you mentioned, in which take didn't work.
Unfortunately, the metadata-schema document is out-of-date. The structure of the Breeze metadata JSON format has changed since then. You are better off looking at an example of current metadata, and following the Metadata by Hand guidelines.

Implementing RESTful field query-string parameter

Based on the recommendation by APIGEE in their RESTful API Design blog post I wish to implement the fields query-string parameter to allow mobile application clients to restrict the content returned from a single RESTful API call. For example:
domain.site.com/rest/accounts/{id}?fields=name,id,age
If the fields parameter is omitted then a complete account resource will be returned. My question is how would I implement this on the server using Jersey (for example). Since Jersey makes it easy to return an Account POJO but I am unsure how to restrict the fields of the resulting JSON object based on the 'fields' query-string parameter.
There's not an automatic way to do it. Your service should load the entire object and then null out the fields you dont' want. Make sure the beans are annotated to ignore null fields in the json serialization and then return the object after you've modified it to remove the fields you dont' want.