掲示板 Forums - Interested in working with a renshuu API?
Top > renshuu.org > Developer corner
Page: 2 of 8
Getting the posts
Page: 2 of 8
Top > renshuu.org > Developer corner
That's a good point! put = add, delete = delete. I do know a bit about rest apis, but I am relatively new to all of this.
I feel like it'd help to keep /word/ID/action, though, so the ID is always in the same place?
Anyway, this is very helpful, thanks!
Alright, I have a single endpoint available for testing! I have not yet added *visible* error handling yet, response codes, etc. Data is validated, it's just that if it fails, it won't really let you know (yet).
To get your API key, go to the experimental panel in Settings. Reset feature for the api key will be added after.
Pass the api key as an authorization header:
Bearer APIKEY
All endpoints should be attached to https://new.renshuu.org/api
[GET] /v1/word/search
{
value: "ねこ"
pg: 0 //optional
}
[GET] /v1/word/:id
{} //no arguments. Will return list of presence (or absence) in related materials
[PUT] /v1/word/:id
{
list_id:
sched_id: //must include one or the other. Will add word to that list or schedule (if not already present)
}
[DELETE] /v1/word/:id
{
list_id:
sched_id: //must include one or the other. Will remove word to that list or schedule (if not already present)
}
I'd like to harden this one, and then extend it out to kanji, grammar, and sentence endpoints. Simultaneously (much easier, since it's GET only), will start working on user stats, schedules, etc.
I might be mistaken, but those GET requests look like POSTs. That’s a no-no.
So as long as there is at least one possible argument not in the url, post? I suppose it would make sense then to keep everything post, since there's always the chance that an expansion of the endpoint could result in additional options/settings.
If you want to include a request body, it can't be a GET. For GET requests, you can use query parameters instead: /v1/word/search?value=x&pg=0
ah, interesting. This all makes sense to me, I've just never had to put it all together in an api.
I'll adjust them to proper get's afterwards.
I've managed to get the search endpoint kind of working.
Using the following command, it works. Note that the bearer token is missing. Omitting the header seems to behave in the same way (working). Using invalid or my own api key results in a response of an empty array ([]). In short, the api key checking is broken.
curl -s -H 'Authorization: Bearer ' 'https://new.renshuu.org/api/v1/word/search?value=neko'
I could not make GET /v1/word/:id work at all. It always returns an empty array. I have not tried the others since the inputs seem to depend on the output of this endpoint.
I had a shortcut stuck in for myself until I got the auth system in place, and it had not been removed. Should be good now. Now: it will not return proper error states yet, that's on the to-do.
I have not added a logger to the newer api, but I'll add that soon so I can start seeing what is getting sent in and out. Been dealing with a headache most of the day, so work did sidetracked somewhat.
I believe the :id one should be better now - I had actually written the api calls wrong in the earlier post, but adjusted the code so it matches what's in there.
Works fine from python.
>>> res=requests.post(base+"/v1/word/search"+"?value="+"gomakasu", headers=header).json() >>> pprint(res) {'count': 1, 'per_pg': 50, 'pg': 0, 'query': 'ごまかす', 'result_count': 3, 'total_pg': 0, 'words': [{'aforms': ['誤摩化す', '胡麻化す'], 'def': ['to deceive, to cheat, to swindle', 'to falsify, to misrepresent, to lie about, to tamper ' 'with, to doctor, to cook', 'to evade (a question, taxes, etc.), to dodge, to gloss ' 'over (a mistake, fault, etc.), to smooth over, to get ' "one's way out of (a difficult situation), to explain away", 'to embezzle, to pocket'], 'hiragana_full': 'ごまかす', 'id': '5999', 'is_common': True, 'kanji_full': '誤魔化す', 'markers': ['JLPT N1', 'News/Web 10k'], 'pic': ['https://iserve.renshuu.org/img/wpics/11029.jpg'], 'pitch': ['ご⭧まか⭨す'], 'reibuns': '12', 'typeofspeech': '(す verb/transitive)'}]}
Where in the result are the "rarely written as" forms? This word has one and it's in the 'kanji_full' property, but potentially words could have multiple rarely written forms, right? They don't seem to be included in the 'aforms'.
Why is the 誤魔化す even marked as "rarely written"?
In JMDict, the entry is "誤魔化す[ateji];誤摩化す[ateji,rK];胡麻化す[ateji,rK]". So the last two are marked as rare Kanji form but the first one isn't.
One endpoint I think would be cool would be a lookup by JMDict entry ID instead of the renshuu ID if possible. (or return it as a proterty in the search results)
api logs are added, rate limiting will come in soon. I'll get those extra fields exposed soon.
Also, it was on my backburner, but another user reminded me that I need to think about what data is actually exposed. I have no plans to allow user lookup outside of the authenticated user, but I think it's definitely worth considering what user-made data should be available through the api (like usage notes, mnemonics, etc.)
Not sure if it's an issue on my side, but I can't get the request to add a word to a list to work. The server responds with the info about the word and a 200 return code, but the word doesn't get added.
What I send:
send: b'PUT /api/v1/word/375520 HTTP/1.1\r\nHost: new.renshuu.org\r\nUser-Agent: python-requests/2.31.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Bearer XXXXXXXX\r\nContent-Length: 22\r\nContent-Type: application/json\r\n\r\n'
send: b'{"list_id": "5412154"}'
I've noticed that one too.
In addition, another bug is that the search endpoint should only respond to GETs. Evidence is in イクト's post above where the python code does a POST request to the search endpoint.
Maybe the root of these bugs is the same.
Hmm - I'm not quite sure what's going on, but the logger (which grabs all parameters, sent by either GET/PUT or POST) which grabs everything before any processing is done, did not see the list_id argument. I'm running my tests through php's curl functions, so I cannot give you something that I think will help you, but it seemed to get everything except for that list_id argument.
I've noticed that one too.
In addition, another bug is that the search endpoint should only respond to GETs. Evidence is in イクト's post above where the python code does a POST request to the search endpoint.
Maybe the root of these bugs is the same.
I also noticed that when I looked at my post again "why did I use post there???" and changed it to get.
Fixed post issue. Do not believe it is related to the other issue.
I'm also wondering what best response codes will be to implement - a quick research online leads me to much longer lists than I probably need. Aside from bad auth, I guess I see it either being
1. invalid endpoint
2. valid endpoint, but not all required fields
3. valid endpoint, required fields, no success (example: try to add word to schedule that already has it)
4. valid, required, required fields, no results on GET. (this is probably success, as there were no errors, just no results)
I'm guessing 1/2/3 require an error-based code, but not sure what would be ideal.
Hmm - I'm not quite sure what's going on, but the logger (which grabs all parameters, sent by either GET/PUT or POST) which grabs everything before any processing is done, did not see the list_id argument. I'm running my tests through php's curl functions, so I cannot give you something that I think will help you, but it seemed to get everything except for that list_id argument.
also tried it with curl from the commandline but the result is the same.
curl --verbose -X "PUT" -H "Content-Type: application/json" -H 'Authorization: Bearer xxxxxx' -d '{"list_id": "5412154"}' https://new.renshuu.org/api/v1/word/375520
1 sounds like 404 or 405 depending on the endpoint and method.
2 sounds like 400.
3 and 4 seem like normal operation. 200.
3 could be 409 too but it seems more graceful to just return success, especially since it is modifying a boolean.
I wonder if putting list_id as a query parameter would work. If it does, then the server is probably reading only the query parameters and not the request body.
I wonder if putting list_id as a query parameter would work. If it does, then the server is probably reading only the query parameters and not the request body.
https//new.renshuu.org/api/v1/word/375520?list_id=5412154
Yup, that seems to work.