Giter Club home page Giter Club logo

Comments (8)

tomchristie avatar tomchristie commented on September 28, 2024

I wouldn't create a new pip package, or PR into this repo, but you would need have a custom codec to deal with 'application/problem+json', yes.

from coreapi import codecs

# A custom codec to handle 'application/problem+json' responses.
class ProblemJSON(codecs.JSONCodec):
    media_type = 'application/problem+json'

# Instantiate our client with set of codecs we want to support.
decoders = [
    codecs.CoreJSONCodec(),  # Or whatever you use for your API schemas.
    codecs.JSONCodec(),          # For standard responses
    ProblemJSON()                     # For error responses
]
client = Client(decoders=decoders)

It's possible that we could consider including 'application/problem+json' by default, but I don't think that's necessarily something we'd want to do just yet.

from python-client.

tomchristie avatar tomchristie commented on September 28, 2024
  • This that resolve things adequately, or is that too awkward for your needs?
  • Out of interest, what media type are you exposing your API schemas?
  • Any pain points, or general points of confusion, with using coreapi as a client library?

Thanks, Dan!

from python-client.

danballance avatar danballance commented on September 28, 2024

Okay thanks, that will work fine I guess. Although It's not going to be quite as "plug-and-play" for our customers then because I'm going to need to provide an additional decoder class before they can access our API properly. So I guess I will lean towards providing an example client that they can install from pip/github that sets CoreAPI up correctly for them with this additional class.

In terms of non-error responses I am returning application/hal+json hypermedia resources. For the API schema itself I'm using OAI/Swagger2. I have built a kind of in-house schema on top of these formats that we're using internally to automate a lot of the repetitive boiler plate required for many API operations. It's working pretty nicely so far - lots of automatic code generation of the API server code as well as client libraries such as Core API working, pretty much, out of the box.

There are always one or two teething issues to solve though. The next one actually is authentication. My API is using the OAuth2 password flow. Are there any plugin options for authentication or is this something I'll need to add myself?

from python-client.

tomchristie avatar tomchristie commented on September 28, 2024

Although It's not going to be quite as "plug-and-play" for our customers

On second thoughts maybe we could provide this built-in. (Or something like have the default decoders automatically be whatever plugins are available, so that it's only a pip install away, and nothing else)

The next one actually is authentication. My API is using the OAuth2 password flow. Are there any plugin options for authentication or is this something I'll need to add myself?

At the moment the best you'd get would be adding the auth endpoints to the scheme, tho you'd still need to create a new client once you do have the auth token. And yes, addressing this is absolutely on the list.

from python-client.

danballance avatar danballance commented on September 28, 2024

Thinking about this a little further, maybe for now I will go down the route of a separate pip package then - even though the code will be ridiculously trivial. As you say, it's just a pip install away and I can still point people directly to this project and just say in the docs that they need to ensure they install a specific list of pip packages with it.

Edit: I'm here actually meaning a pip package that can be installed from github - that probably I'll just include in a requirements.txt file. I'm not meaning an official pip package.

In terms of authentication, since this PR in the Swagger-UI project my users can now authenticate directly in Swagger-UI when they are exploring the API. (Which is pretty cool!) I'll have to have a think about what I can do here in the meantime in terms of authenticating our customers with CoreAPI - obviously authenticating to the API is an absolutely critical feature. Is it worth me opening an issue for authentication plugins or do you have this covered off elsewhere?

thanks for your help and prompt replies!

from python-client.

tomchristie avatar tomchristie commented on September 28, 2024

Is it worth me opening an issue for authentication plugins or do you have this covered off elsewhere?

Opening the issue makes sense, yup.

There's a coupla different issues worth talking through there:

  • What set of auth policies might we need to support?
  • What does an example auth flow look like?
  • What information does the scheme itself need to present in order to make that possible?

from python-client.

danballance avatar danballance commented on September 28, 2024

In terms of workarounds or interim solutions, I've noticed that I can pass in credentials to the client via the transports list. This is just a simple test, but this authenticates me okay to my local dev server.

transports = [
    HTTPTransport(credentials={"localhost": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"})
]
client = Client(decoders=decoders, transports=transports)

Is there any chance you could explain a little more about the credentials variable/attribute and the purpose behind the host check? I'm just wondering if I can find a way to piggy back on this somehow. Perhaps the token generation and caching could be done outside of CoreAPI for now and the client is then instantiated with a transport that has a bearer token ready to go.

It's not ideal but it might be okay as a workaround until #115 is complete.

from python-client.

danballance avatar danballance commented on September 28, 2024

Final comment for the day from me :)

So I've decided to import a set up function that makes things nice and easy for our customers. This particular use case is for the example/tutorial section from our API docs and for this section at least I want things to be really easy without needing to understand too much about how things are working internally. I end up with example code like the following that seems to work for my purposes:

from orbtalk_api_utilities import setup_coreapi
client, schema = setup_coreapi(auth_endpoint, auth_username, auth_password, schema_url)

print "Creating new call for extension 1000..."
doc_call = client.action(schema, ['pbx.Call', 'resources.pbx.call.create'], params={
    "call": {
        "domainId": domain,
        "origExtension": extension,
        "destination": destination
    }
})
print "...create call result was:"
print doc_call

Happy days.

from python-client.

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.