Skip to content

Conversation

@marcelldls
Copy link
Contributor

An additional "backend" for FastCS which provides a RestAPI.
The API is fully discoverable and demoable from the autogenerated "Swagger gui" at "{domain}/docs" and the schema can be retrived from "{domain}/openapi.json", all thanks to FastAPI.

The following considersations have been taken to conform with restful design:

  • Attributes can be read using a GET request to "{domain}/{attribute-name}" (note if sub-controller then {domain}/{subcontroller name}/{attribute-name}" etc.)
    • A successful request receives response of status code 200 and a payload of json: {"value": value}
  • Attributes can be written using a PUT request to "{domain}/{attribute-name}" etc.
    • A PUT request is used rather than a GET of "{domain}/{attribute-name}/{value}" to not be triggered accidentally (not "safe")
    • A PUT request is used over a POST as the action is idempotent
    • The request would have a payload of json: {"value": value}
    • A 204 response to confirm the request as there is no information to return
    • FastAPI automatically deals with wrong types an will issue a 422 error with message
  • Commands can be triggered using an empty PUT to "{domain}/{command-name}"
    • A 204 response to confirm the request as there is no information to return

I follow a similar pattern to the Tango "backend" to create the server and do some testing, so any feedback from #66 should feed into this

@marcelldls marcelldls requested a review from GDYendell November 4, 2024 10:27
@codecov
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 94.80519% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.74%. Comparing base (5256be3) to head (ff7da53).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fastcs/backends/rest/rest.py 95.58% 3 Missing ⚠️
src/fastcs/backends/rest/backend.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #69      +/-   ##
==========================================
+ Coverage   86.10%   86.74%   +0.63%     
==========================================
  Files          23       25       +2     
  Lines         979     1056      +77     
==========================================
+ Hits          843      916      +73     
- Misses        136      140       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@marcelldls marcelldls force-pushed the rest-backend branch 3 times, most recently from 0c01945 to 59f76b5 Compare November 12, 2024 09:15
Copy link
Contributor

@GDYendell GDYendell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few comments.

I assume the test utilities have just been copied from the tango PR for now and most of it can be shared between backends once merged?

@marcelldls
Copy link
Contributor Author

Looks good. A few comments.

I assume the test utilities have just been copied from the tango PR for now and most of it can be shared between backends once merged?

Thank you for the review Gary. I found a few tricks when I did the web api testing and fed this back into Tango. Since we will add p4p I did not look at softioc...

@marcelldls
Copy link
Contributor Author

@GDYendell Updated the testing inline with feedback from #66

@marcelldls marcelldls marked this pull request as ready for review November 21, 2024 10:09
@GDYendell GDYendell changed the title First attempt rest api Add Rest API Backend Nov 21, 2024
@GDYendell GDYendell merged commit 9d3d9bf into main Nov 21, 2024
17 checks passed
@GDYendell GDYendell deleted the rest-backend branch November 21, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants