diff --git a/segments/plug/README.md b/segments/plug/README.md index 49d0a60..ca8e5f6 100644 --- a/segments/plug/README.md +++ b/segments/plug/README.md @@ -12,3 +12,6 @@ * [Transforms]({{book.transforms}}) * [Initial State]({{book.initial_state}}) * [Indexers]({{book.indexers}}) + +### Usage +* [Rest Proxy]({{book.rest}}) diff --git a/segments/plug/rest.md b/segments/plug/rest.md new file mode 100644 index 0000000..7a8b66d --- /dev/null +++ b/segments/plug/rest.md @@ -0,0 +1,31 @@ +# REST Proxy + +The REST proxy is a convention for structuring and communicating between clients and Web Servers through the [HTTP Protocol](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol). + +Plug makes use of this Proxy to enable you to build clients, be it Browser Based Clients, or Terminal Clients, that can query and alter the state of your Plugin. + +If you want to visually render a ledger of user balances and transactions stored within a browser client, or wish to view your own balance by entering a command in your command line, you will need to understanding how to use REST with Plug. + +## What can plug do with REST? + +If you run your Plugin and go to http://localhost:8181/_swagger, + +Swagger builds a nice interface for your REST routes within Plug, and with this page you can see the many types of HTTP requests you can send sorted into categories. + +Most of the routes can also be interacted with through this interface, so this is a great place to start for understanding the bredth of Plug with REST. + +Because the URL bar of your browser sends GET requests, try going to http://localhost:8181/_swagger#!/status/get_api_v1_status in your browser. You should see the response text rendered, detailing the status of your running node. + +## Postman + +[Postman](https://www.getpostman.com/) is a great application that allows you to send HTTP requests of any method. We encourage you to use this tool over the swagger interface when it comes to testing your Plug REST endpoints. + +By using Postman, you will be able to build out a full Plugin without needing a client side to trust that your code is working. This is a form of manual testing, so you should still write some [Unit Tests](../python/unit_testing) too. + +## Standout Endpoints + +| Endpoint | Method | Usage | +| --- | --- | --- | +| /_api/v1/transaction | POST | Apply a posted Transform to the state | +| /_api/v1/transaction/{transaction_hash} | GET | Receive information about a past transaction (transform, etc) | +| /_api/v1/query/{target}/{indexer}/{key} | GET | Retrieve information from the state sorted by model, indexer and key | diff --git a/student-guide/SUMMARY.md b/student-guide/SUMMARY.md index ac1bccd..51f5975 100644 --- a/student-guide/SUMMARY.md +++ b/student-guide/SUMMARY.md @@ -30,3 +30,4 @@ We have provided links to resources you will want to read through for technical * [Transforms](segments/plug/transforms.md) * [Indexers](segments/plug/indexers.md) * [Initial State](segments/plug/initial_state.md) + * [Rest](segments/plug/rest.md) diff --git a/student-guide/book.json b/student-guide/book.json index d4fa3f7..fa84693 100644 --- a/student-guide/book.json +++ b/student-guide/book.json @@ -18,6 +18,7 @@ "plug": "/segments/plug/", "setup": "/segments/plug/setup.md", "transforms": "/segments/plug/transforms.md", + "rest": "/segments/plug/rest.md", "decentralisation": "/segments/crypto/decentralisation.md", "blockchain": "/segments/crypto/blockchain.md", "solution": "/segments/challenges/free-money-solution.md",