Giter VIP home page Giter VIP logo

Comments (11)

bacardi55 avatar bacardi55 commented on May 19, 2024 1

jsonify in this case transform the content of the yaml into a json output (and add headers and a few things).
But whatever yaml file you jsonify, the result will be a correct json.
The content however, is where the jsonapi standards indicate what the json must contains.

eg:, for /synapses, kalliope API returns an array of synapses like

{
  "synapses": [
    {
      "name": "say-hello-fr", 
      "neurons": [
        {
          "say": {
            "message": [
              "Bonjour monsieur"
            ]
          }
        }
      ], 
      "signals": [
        {
          "order": "bonjour"
        }
      ]
    }
  ]
}

whereas with the jsonapi standard, the content should be something like:

{
  "links": {
    "self": "http://kalliopeHost:5000/synapses"
  },
  "data": [{
    "type": "synapses",
    "id": "1",
    "attributes": {
      "name": "say-hello-fr", 
      "neurons": [
        {
          "say": {
            "message": [
              "Bonjour monsieur"
            ]
          }
        }
      ], 
      "signals": [
        {
          "order": "bonjour"
        }
      ]
    }
  }]
}

That being said, it is not that important to follow it but JS frontend can work with very limited amount of custom code if the API follow it (eg: https://github.com/jakubrohleder/angular-jsonapi for angularjs or http://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html in core of emberjs).

But

from kalliope.

Sispheor avatar Sispheor commented on May 19, 2024

Does it returns all synapses in included yaml or just the "include" pointer?

from kalliope.

Sispheor avatar Sispheor commented on May 19, 2024

I found the problem. I chose to send the loaded yaml file directly instead of serialize object per object.
I need to update this part...

from kalliope.

bacardi55 avatar bacardi55 commented on May 19, 2024

As a more global remark on the API, I think the API should:

  • be JsonAPI compliant (so easier to create backend using angularjs or emberjs frontend)
  • Be configurable to authorize cors request in case frontend has not the same origine as kalliope (origine being host + port + scheme). It might often be the case as a JS app might not run on the same port as kalliope.

from kalliope.

LaMonF avatar LaMonF commented on May 19, 2024

yes I agree, we did not spend much time on the API, we need to investigate deeper on those 2 points.

from kalliope.

bacardi55 avatar bacardi55 commented on May 19, 2024

Ok, so I did a quick hack to test something.
By adding the flask-cors library, and adding the 2 lines as per the following diff, I can make my emberjs app working (on port 4200, my node server) and with kalliope on port 5000.

Is this something worth investigating? I could try to set this up as optional (as the authentication part) so that only people allowing CORS request will have this feature?
(obviously the code below is just a quick hack that need better config, eg: for origin acceptance)

diff --git i/kalliope/core/RestAPI/FlaskAPI.py w/kalliope/core/RestAPI/FlaskAPI.py
index 01c3856..298a0bc 100644
--- i/kalliope/core/RestAPI/FlaskAPI.py
+++ w/kalliope/core/RestAPI/FlaskAPI.py
@@ -4,6 +4,8 @@ from flask import jsonify
 from flask import request
 from flask_restful import abort

+from flask_cors import CORS, cross_origin
+
 from kalliope.core import OrderAnalyser
 from kalliope.core.RestAPI.utils import requires_auth
 from kalliope.core.SynapseLauncher import SynapseLauncher
@@ -23,6 +25,8 @@ class FlaskAPI(threading.Thread):
         self.port = port
         self.brain = brain

+        cors = CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True)
+
         self.app.add_url_rule('/synapses/', view_func=self.get_synapses, methods=['GET'])
         self.app.add_url_rule('/synapses/<synapse_name>', view_func=self.get_synapse, methods=['GET'])
         self.app.add_url_rule('/synapses/<synapse_name>', view_func=self.run_synapse, methods=['POST'])

edit: Also, simply adding the line:

self.app.add_url_rule('/synapses', view_func=self.get_synapses, methods=['GET'])

seems to work fine to add a more standard routes to retrieve synapses (GET /synapses)

from kalliope.

Sispheor avatar Sispheor commented on May 19, 2024

be JsonAPI compliant

We are not JSON compliant here?

from kalliope.

bacardi55 avatar bacardi55 commented on May 19, 2024

The API return json but is not really jsonapi compliant (which is a new standard for api that return json for url and response content)

from kalliope.

LaMonF avatar LaMonF commented on May 19, 2024

Actually we are using the jsonify lib to return from the yaml so it seems compliant ... or the lib itself is not

from kalliope.

Sispheor avatar Sispheor commented on May 19, 2024

Ok, thanks for the example.
It seems it's not really implemented a lot yet. Even in professional projects. So, we'll see if we implement it from our side when we will review the Web App for Kalliope client config. It will be in Angular 2 I think.

from kalliope.

Sispheor avatar Sispheor commented on May 19, 2024

Fixed in the v0.4.0.

Now included brains are returned and we've also allowed the remove the last slaches in URL.

from kalliope.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.