question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: REST API handlers

See original GitHub issue

I would like to use an existing JustPy app to also provide a few REST API functions. My current attempt goes like this:

import justpy as jp
import starlette.responses

def status_json(request):
    return starlette.responses.JSONResponse({'status':'okay'})

jp.Route('/api/status',status_json)
jp.justpy(status_json)

which understandably results in AssertionError: Function did not return a web page.

Could you please help me hook into scarlette inside JustPy so that the request can return JSON, for some endpoints?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eudoxoscommented, Nov 18, 2020

Thanks @elimintz, that is what I found out as well 😃 The API interface is not complex in this case so I’d like to keep it neatly together with pages served by JustPy.

0reactions
eudoxoscommented, Dec 3, 2020

#182 would allow returning JSONResponse.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developing request handlers - Vespa Documentation
Implementing a request handler. Upon receiving a request, the request handler must consume its content, process it, and then return a response. The...
Read more >
fabulator/rest-api-handler - GitHub
This library will help you with requests to REST APIs. It uses Fetch API which isn't supported by node and some older browsers...
Read more >
Best practices for REST API design - Stack Overflow Blog
In this article, we'll look at how to design REST APIs to be easy to understand for anyone consuming them, future-proof, and secure...
Read more >
Creating custom REST resource handler to perform mapping
A REST call requires the creation of a resource handler. The resource handler represents the entry point for resource requests and is annotated...
Read more >
REST API Best Practices – REST Endpoint Design Examples
4. Use Status Codes in Error Handling ... You should always use regular HTTP status codes in responses to requests made to your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found