REST API

domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

REST API

Post by domob »

Reviving the REST API discussion - because Bitcoin Core recently merged a patch that includes a REST API in addition to JSON-RPC. It can retrieve blocks and transactions by hash, as JSON (like "getblock" / "getrawtransaction (verbose)" format), HEX and binary.

For the future, we could think about adopting that interface as well. We could extend it by a query for names (obviously). I'm thinking about the following extension:

Code: Select all

GET http://host:port/rest/name/name.json
  -> returns JSON similar to "name_show"

GET http://host:port/rest/name/name.bin
  -> returns the name's value as raw "binary"

GET http://host:port/rest/name/name.hex
  -> returns the name's value hex-encoded
I think that's the natural extension of Bitcoin's interface to names. It allows to build a public API server that can be used to resolve names (among other things).

Questions:

1) Does this solve (most) of the problems the original REST discussion was about? Is this interface enough to support all or at least the most important use cases?

2) Since names can (and usually even do) contain a "/" character, it may be unnatural to query by the literal names in the REST URI. Should we encode the name instead in some way (hex or urlencode come to mind - they are easy to use from probably almost any programming language)? Or define rules like "the name is everything (including slashes, dots and so on) after "/name/" and before the last "." in the query"? That seems strange and doesn't allow binary names. How is this usually done in REST APIs?
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

cassini
Posts: 336
Joined: Sun May 26, 2013 6:36 pm

Re: REST API

Post by cassini »

This is an excellent idea, IMO. We shouldn't call it "REST", though. If the URI has nothing to do with the application state it cannot be RESTful (remember: REST = Representational State Transfer).
See Roy T. Fielding's comments: http://roy.gbiv.com/untangled/2008/rest ... ext-driven

For an answer to your question #2 please consult a webbrowser of your choice. ;)
Create an HTML file containing this code:

Code: Select all

<html><body>
<form action='/history'>
Domain or ID: <input type='text' name='namecoinname' value='d/wecan'><br />
<input type='submit' value='Show history'>
</form>
</body></html>
and view it in your browser. Then click "Show history". It hopefully gives you an http 404 error, but watch the address line of the browser:
d/wecan automatically converts to d%2Fwecan

domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

Re: REST API

Post by domob »

Well, I didn't invent the term "rest" - Bitcoin devs did.

So if I interpret your suggestion correctly, we should be using urlencode for the name? (Which is what you mention.) Sounds like a good idea.
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

Re: REST API

Post by domob »

Here you go:

http://chain.huntercoin.org:8336/rest/n ... fdomob.bin
http://chain.huntercoin.org:8336/rest/n ... fdomob.hex
http://chain.huntercoin.org:8336/rest/n ... domob.json

And testnet:

http://chain.huntercoin.org:18336/rest/ ... foobar.bin

No guarantee that I will leave that server open, though. It should just be understood as demonstration. But if someone wants to set up a real "official" server with the interface, I'd be happy to support the effort as much as I can.
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

cassini
Posts: 336
Joined: Sun May 26, 2013 6:36 pm

Re: REST API

Post by cassini »

Well done!
I've tested three keywords so far: name, tx and block. Are there any others?

Is the code already on github? I've been able to spot the corresponding commits in the Bitcoin repo but couldn't find anything at github.com/namecoin/namecoin.

domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

Re: REST API

Post by domob »

cassini wrote:Well done!
I've tested three keywords so far: name, tx and block. Are there any others?
Not that I'm aware of. Other things are probably not Namecoin specific, so could be discussed with the Bitcoin devs.
cassini wrote:Is the code already on github? I've been able to spot the corresponding commits in the Bitcoin repo but couldn't find anything at github.com/namecoin/namecoin.
It is in domob1812/namecore.
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

indolering
Posts: 801
Joined: Sun Aug 18, 2013 8:26 pm
os: mac

Re: REST API

Post by indolering »

I think that the API should (to some degree) support namespace specific queries. For example, I would expect rest/d to return a list of all names in that namespace.

I'm guessing you already thought of this, but it should return json formatted records by default.
DNS is much more than a key->value datastore.

biolizard89
Posts: 2001
Joined: Tue Jun 05, 2012 6:25 am
os: linux

Re: REST API

Post by biolizard89 »

indolering wrote:I think that the API should (to some degree) support namespace specific queries. For example, I would expect rest/d to return a list of all names in that namespace.

I'm guessing you already thought of this, but it should return json formatted records by default.
I guess that would be analogous to the name_filter RPC call. I have no objection to having something like name_filter in the REST API. @domob, thoughts on this?
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5

domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

Re: REST API

Post by domob »

biolizard89 wrote:
indolering wrote:I think that the API should (to some degree) support namespace specific queries. For example, I would expect rest/d to return a list of all names in that namespace.

I'm guessing you already thought of this, but it should return json formatted records by default.
I guess that would be analogous to the name_filter RPC call. I have no objection to having something like name_filter in the REST API. @domob, thoughts on this?
I think this is a good idea. If we work out a spec for the call format, it should be relatively easy for me to implement.
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

indolering
Posts: 801
Joined: Sun Aug 18, 2013 8:26 pm
os: mac

Re: REST API

Post by indolering »

Honestly, I don't see a whole lot of demand for a REST api, I wouldn't put too much effort into it.
DNS is much more than a key->value datastore.

Post Reply