Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite API to parse JSON content body in POST and DELETE requests #156

Closed
wants to merge 10 commits into from

Conversation

db-2001
Copy link
Collaborator

@db-2001 db-2001 commented Apr 7, 2024

Copy link
Owner

@C9Glax C9Glax left a comment

Choose a reason for hiding this comment

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

Looks more readable than mine.
Left a few things I would improve, but other than that, looks ready to merge (since the old uri-method can still be used)

None

- Request Body:
None
Copy link
Owner

Choose a reason for hiding this comment

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

Can have an optional body, to get a specific job

{
jobId: ${Tranga Job ID}
}

See

tranga/Tranga/Server.cs

Lines 172 to 176 in 5f03b0d

if(!_parent.jobBoss.jobs.Any(jjob => jjob.id == jobId))
SendResponse(HttpStatusCode.BadRequest, response);
else
SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs.First(jjob => jjob.id == jobId));
break;

Tranga/Server.cs Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

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

I can't think of a good reason why we should split Parameters and Body...

Copy link
Owner

Choose a reason for hiding this comment

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

It's all getting thrown into the same Dictionary, so having a key-value table sounds like a better idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I agree, I'll just make them the same dictionary if that's what you meant

Copy link
Owner

Choose a reason for hiding this comment

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

I mean in the md file you don't have to split them into "Parameters" and "Request Body"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, okay, I was kinda following the Kacita API docs guide, but yeah

- `{jobId}`: Tranga Job ID

- Request Body:
None
Copy link
Owner

Choose a reason for hiding this comment

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

{
	"jobId": ${Tranga Job ID}
}

None

- Request Body:
None
Copy link
Owner

Choose a reason for hiding this comment

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

optional, to just update a single manga

{
internalId: ${Tranga Manga ID}
}

}
```
#### [POST] /Settings/userAgent
Updates the user agent that Tranga uses when scraping the web
Copy link
Owner

Choose a reason for hiding this comment

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

when left empty, resets it to the default

Encoding encoding = request.ContentEncoding;
StreamReader reader = new StreamReader(body, encoding);
string s = reader.ReadToEnd();
Dictionary<string, string> requestBody = JsonConvert.DeserializeObject<Dictionary<string, string>>(s);
Copy link
Owner

Choose a reason for hiding this comment

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

Probably want a try-catch so we dont crash every time we get a request that has for example integers, booleans, arrays, or nested objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call

@C9Glax C9Glax linked an issue Apr 19, 2024 that may be closed by this pull request
@C9Glax C9Glax mentioned this pull request Apr 19, 2024
@db-2001 db-2001 closed this Apr 20, 2024
@db-2001 db-2001 deleted the json-api branch April 20, 2024 18:05
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.

Rewrite API to use JSON Content Body
3 participants