Fetch data that is not a registered react-admin resource - react-admin

Using react-admin, I have build an ExpressJS API including a GraphQL endpoint. All my resources in react-admin are using the graphql data provider. For a specific resource, I'm looking to fetch some configuration from my API endpoint to generate the form based on the context. I will try to create a mock example as I can't use the actual application's lingo.
For example, if I edit resource Post, and I assign a specific type "Photo", then I want some specific metadata to be saved in the form. My issue is the specific metadata object is coming from the API configuration for type "Photo". So if I select type "Photo", I want to save "Capture Date", "Camera Make", "Camera Model", etc.
The backend configuration would probably be in the form of a JSON schema describing the fields, the label, the key and the type of input (text or password).
TLDR: I want to fetch a configuration in the API and use it in the app to generate a list of form inputs. How can I do this without registering the call as a resource, since I don't feel like it is?
Edit
I haven't tried anything yet as I was asking a theoretical question to see if anybody had a "proper way" to suggest. My two options were the following:
Create a Resource for the PostType and it would simply return the list of fields as a JSONschema when called with GET_ONE. This would make use of the dataProvider to do the fetching.
Simply use fetch in my form and call my API endpoint directly.

Related

CKAN: how do I update/create the data dictionary of a resource using the api?

My company is using a CKAN instance configured with Data Store and DataPusher. When a CSV file is uploaded to CKAN, DataPusher sends it to the DataStore and creates a default Data Dictionary for the resource. The Data Dictionary is a very nice feature to display the description of data fields for the users. Here is an example (it is in Brazilian Portuguese):
I can update the Data Dictionary using the UI, or it can be sent as part of the Fields passed to datastore_create().
My problem, is that I don't control the call of datastore_create() because this method is automatically called buy the DataPusher service.
I want to programmatically set the values of the Data Dictionary, but I can't find the api call that allows me to do it. An api call that update the Fields metadata. Can I do it using the Api? Or maybe it is possible create it when I create the data resource. I'd like a code example.
You can use the API call datastore_create on top of an existing table. This will not impact the data in the table.
You should use the datastore_search to check the format of how the dictionary is saved in one of your resources (result->fields->info). Use that as your base, make the desired changes, and use it in the body of the datastore_create call.
Unfortunately, the API call datastore_info does not give you back that information.
The majority of the CKAN UI functionalities can be made through the API as well. In this case, you can make use of the "datastore_create" by the controller --> See Code here.

Consuming TFS Web Hooks (Post via HTTP)

Is there a specific request format that the webhooks have? I am using the Pull Request Updated event, and I am trying to deserialize into a class, but I do not know what fields I will need. Is there a class or example of the request content details for the different events?
As far as I know, there isn't a generic template for the HTTP post request/response from TFS.
The TFS HTTP post JSON request/response format is based on the specific action.
For example, for the web hooks whenever a work item is updated.If I update a description field, I am getting one format and if I add a child work item, I am getting another format.
However for the specific event, you can check the response format, then get the useful information which you needed.
Please refer to Send JSON representation to a service for more information.
And at the end of the Q&A part there is a sample JSON.

ASP.NET Core Displaying data in View from Api

I am creating Cars store in Asp.Net for my school.
I built an Api Method:
[HttpGet("api/brands/{brandName}/models")]
public IActionResult Get(string brandName)
{
{
var model = _context.getBrandByName(brandName);
return Ok(model.Models.ToList());
}
}
An it works when I am checking it with Postman.
Now I would like User to choose brandName from selection list in the website and show him avaliable models.
In other words I dont know how to use this Api to get Data displayed.
Any help will be strongly appreciated
RESTful Web services are one way of providing interoperability between computer systems on the Internet. REST-compliant Web services allow requesting systems to access and manipulate textual representations of Web resources using a uniform and predefined set of stateless operations.
from Wikipedia.
This means, the REST API's only concern is to provide the data to work in a uniform and predefined set of operations, where those operations take the HTTP Verb that was used in consideration.
in your example, your GET route, should only be api/brands/{brandName}
the default in rest api, http verbs say:
GET - getting one element or a list
POST - creating
PUT - updating
DELETE - removing
in your application, the best approach would be something like:
GET /api/brands will get ALL existing brands
GET /api/brands/<brand_name> will get just one brand
POST /api/brands will create a new brand
PUT /api/brands will edit an existing brand
DELETE /api/brands will delete an existing brand
from your question:
Now I would like User to choose brandName from selection list on the website
the website would then request a GET to the route /api/brands to get the list of all of the brands.
This is the REST API part, it concerns ONLY in providing the right data to the system that request it.
if you want to create a website in order to CONSUME this data, you can easily create a new web project in your solution and request the data that the API provides, making the Website completely "blind" from where the data comes from, as it only asks for the data itself.
Making the whole system much easier for updated and maintainability.
In other words I dont know how to use this Api to get Data displayed.
The main purpose of REST API is to expose data not to display it by using any kind of UI framework.
If you think you need to manage the full stack of your application end-to-end. I mean from User interface to your database then you must think at implementing the V of the MVC pattern bu return a view and not just a data. ASP.Net Core can help you with that. Follow this tutorial, it explains a lot about this pattern in ASP.Net Core MVC.

Passing params to POST API

I am new to designing REST APIs. I have trying to create following APIs for online game play
GET domain/api/games // return all games
POST domain/api/games // create a new game on behalf of current user
Now my issue is that when I try to create game using POST, I want userId to be sent to the API. I am not sure how to do this. Also note that I have another get API to get details of individual game, something like
GET domain/api/games/{gameId}
so I cannot pass userId to POST like domain/api/games/{useID} as it will conflict will above API.
So how do I pass usedId to POST. Also I don't want to use query params. Any suggestions to design this would be great.
When you are making a POST to a service, the parameters you communicate are known as BODY params, they don't go on the query string.
Different technologies have different APIs for interacting with POST params, but the underlying theory is the same, and is described by the W3C HTTP standard
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
The specifics of how to use POST params vary depending on the language and technology you're using. For example, if you are using jquery, there are a couple different ways to do it, with with the $.post('url', data, callback) method or with the $.ajax(...) option.
http://api.jquery.com/jquery.post/
http://api.jquery.com/jquery.ajax/
When reading POST params on the server, you'll generally access them using some some sort of request object, that will store your parameters in memory for you to access. This is highly dependent of the language and framework you're using, but here are links to some common ones:
NodeJS/express: http://expressjs.com/4x/api.html#request
PHP: http://php.net/manual/en/reserved.variables.post.php
ASP.Net: http://msdn.microsoft.com/en-us/library/system.web.httprequest.params(v=vs.110).aspx
Java/Spring: https://spring.io/guides/gs/handling-form-submission/
It should be either part of the context (you can pass it through header) or part of the game object. I prefer the context option, the httpheader can contain some auth bearer token so that you can figure out the user on the backend through the token.

Restful api custom types

So I am building a restful api allowing users to send events.
There are "standard" events like birthday, wedding, etc that each have their separate properties. So if someone sends data for type = birthday they can also specify the parameters date_of_birthday, new_age, etc. If they send type = wedding, for example, they have to specify different properties.
So basically when they make /event/create api call, they specify a type and a list of properties based on that type. If they want to specify a "custom" type they can. In that case the properties they specify are up to them.
How best to build this api so that it is true to rest?
To create an event, clients should make a POST request like
HTTP POST: /event
The post parameters should contain the event details and can be of any structure that the application understands.
Create events using POST, this request it self stands for "Create new" event. I would also suggest following structure of your API URIs:
POST /event/birthday //Create new birthday event
POST /event/wedding //Create new wedding event
...
generally:
POST /event/{event_name}
this will help you provide clear structure of the RESTful API. E.g. getting all event types can be retrieved with GET /event, getting all birthdays with GET /event/birthday, getting weddings on 1.1.2014 GET /event/wedding/1-1-2014 etc
Think of your resource URI structure in the same way, you will define a folders and files structure.