NATION

PASSWORD

Server-Sent Events

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Haku
Technical Moderator
 
Posts: 284
Founded: Jan 02, 2018
Corporate Police State

Server-Sent Events

Postby Haku » Thu Dec 26, 2024 5:51 pm

Folowing the server-sent events (SSE) forum discussion thread, the new SSE API endpoint is now live.

To use it, make a GET request to:
Code: Select all
https://www.nationstates.net/api/bucket1+bucket2+nation:nationname+region:regionname+(...)


The available buckets will match the names of the list of buckets available through the World API happenings shard. Buckets for viewing the activity of specific nations or regions can be done using the `nation:nation_name` or `region:region_name` syntax. Note that this is not a filter.

The documentation for this feature is in the server-sent events section of the API documentation.

Note: This feature is still highly experimental and may be a bit buggy. Feedback is appreciated.
Last edited by Haku on Fri Dec 27, 2024 5:19 pm, edited 4 times in total.

User avatar
Ostrovskiy
Ambassador
 
Posts: 1221
Founded: Nov 01, 2019
Left-wing Utopia

Postby Ostrovskiy » Thu Dec 26, 2024 6:17 pm

I assume with this change the old way of doing things will be phased out and eventually banned, correct?

If so, what's the timeline for that?
Warden-Lieutenant, TGW | Elected Director, UDS | Minister of Culture, tPoP
the Lavenderest Collection is pretty cool
SCR#439, SCR#444, GAR#674, SCR#471,SCR#492, SCR#493, Issue #1622, GAR#766


All opinions are solely my own (duh)

User avatar
United Calanworie
Technical Moderator
 
Posts: 5193
Founded: Dec 12, 2018
Democratic Socialists

Postby United Calanworie » Thu Dec 26, 2024 6:26 pm

Ostrovskiy wrote:I assume with this change the old way of doing things will be phased out and eventually banned, correct?

If so, what's the timeline for that?

If your question is "are we removing the happenings events shard," the answer is "not at this time."

If your question is "are we removing reports.html," the answer is yes, and soon-ish.
@queerlyfe | She/Her/Hers
Getting Help Request (GHR) | One Stop Rules Shop (OSRS) | Routine Actions thread | NS Announcements Discord
Script Rules | API Documentation | Approved Image Hosts | How Bots are Regulated | NS Coders Discord

"...against all enemies, foreign and domestic..."
You are such a crybaby [...] all you do is lock threads and be a bitch to people, nobody likes you, you aren’t cool, you lock every thread for stupid reasons, often times not giving a reason, [...] all you do is sit on your computer all day on NationStates, locking threads at a rate 5x higher than any other mod [...] stop trying so hard to impress people, literally nobody like you.
Have a good day

User avatar
Flying Eagles
Envoy
 
Posts: 210
Founded: Nov 04, 2017
Democratic Socialists

Postby Flying Eagles » Thu Dec 26, 2024 7:00 pm

For mobile: Region pages work well enough when all the raiders are in the same region but in other situations the reports page feels borderline mandatory to be an effective chaser since the Activity page is slow to load and region pages obviously won’t work. Bit concerned with this change atm.
Last edited by Flying Eagles on Thu Dec 26, 2024 7:40 pm, edited 3 times in total.
XKI TITO Field Commander

User avatar
East Chimore
Envoy
 
Posts: 316
Founded: Sep 28, 2016
Democratic Socialists

Postby East Chimore » Thu Dec 26, 2024 7:12 pm

:clap:
SSE will make more parts of the game accessible which is always a win, and a bonus of reducing server load is even better! Thank you Haku

User avatar
Darcania
Envoy
 
Posts: 214
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Thu Dec 26, 2024 7:18 pm

It appears that requests to this endpoint currently don't supply ratelimit information in the response headers. Will the initial request be placed under the API ratelimit, or have some form of ratelimit applied?

User avatar
Chacapoya
Secretary
 
Posts: 38
Founded: Oct 03, 2014
Corrupt Dictatorship

Postby Chacapoya » Thu Dec 26, 2024 7:23 pm

I wasn’t expecting to see this implemented so soon! This is a fantastic belated Christmas present, and I’m excited that this opens up a great deal of gameplay to folks who may not have previously been able to participate!
She/Her
Councillor of Foreign Affairs
Ward, Councillor of Culture, and Operations Councillor Emerita
Refugia

User avatar
Notanam
Envoy
 
Posts: 332
Founded: Feb 21, 2019
Civil Rights Lovefest

Postby Notanam » Thu Dec 26, 2024 8:54 pm

dope nice work yall
This is Nota's signature.

User avatar
Haku
Technical Moderator
 
Posts: 284
Founded: Jan 02, 2018
Corporate Police State

Postby Haku » Fri Dec 27, 2024 5:13 pm

Darcania wrote:It appears that requests to this endpoint currently don't supply ratelimit information in the response headers. Will the initial request be placed under the API ratelimit, or have some form of ratelimit applied?

No, the initial request does not count towards the API rate limit at the moment.

There is now a server-sent events section in the API documentation.
Last edited by Haku on Fri Dec 27, 2024 5:13 pm, edited 1 time in total.

User avatar
The Yeetusa
Spokesperson
 
Posts: 182
Founded: Oct 17, 2019
Iron Fist Consumerists

Postby The Yeetusa » Fri Dec 27, 2024 9:27 pm

With the SSE endpoint's data being in JSON, does this mean the rest of the API eventually be moving away from XML in favor of JSON?

User avatar
Vleerian
Spokesperson
 
Posts: 195
Founded: Feb 07, 2022
Father Knows Best State

Postby Vleerian » Sat Dec 28, 2024 6:22 am

With region updates being posted to the happenings feed, this has to be the most impactful change to scripting since the introduction of lastupdate :shock:

Thank you for all the new toys to play with! :twisted:
Vleerian - Also known as Aurum Rider
Creator of FATTKatt and zoomies, Author of The Bacchist Manifesto
Designer of many Malice logos, headers, and flags. Certified Ruffian

User avatar
UPC
Bureaucrat
 
Posts: 58
Founded: Jul 18, 2022
Liberal Democratic Socialists

Postby UPC » Fri Jan 03, 2025 8:19 am

I think that I may be misunderstanding the method of filtering events, but I am running into an issue where I would like to subscribe to a particular bucket, I'll use endo as an example, within a specified region (europeia). Using the happenings API, I would do something like this:

Code: Select all
https://www.nationstates.net/cgi-bin/api.cgi?q=happenings;filter=endo;view=region.europeia;limit=100


And my assumption was that I could do something similar by subscribing to the endo and region:europeia buckets:

Code: Select all
https://nationstates.net/api/endo+region:europeia


But this shows every Europeian happening (RMB messages submitted, WFE changed, etc.) along with every endorsement in the entire world. And from my testing so far, it seems that despite endorsements being logged in the regional happenings feed, they don't appear in the regional SSE feed without subscribing to the endo bucket globally. This 'issue' (assuming it is not intended behavior) also applies to other event categories, like answering issues, changing national fields, and presumably others that I just have not run across yet.
The Words of Radiance of UPC
Delegate of Europeia

(he/they)
Visit Europeia | Join Our Discord | Apply For Citizenship

User avatar
Darcania
Envoy
 
Posts: 214
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Sat Jan 04, 2025 3:18 pm

The OP states that the region: and nation: buckets are not filters, so it seems like that's intentional (emphasis added by me):
Haku wrote:Buckets for viewing the activity of specific nations or regions can be done using the `nation:nation_name` or `region:region_name` syntax. Note that this is not a filter.

User avatar
UPC
Bureaucrat
 
Posts: 58
Founded: Jul 18, 2022
Liberal Democratic Socialists

Postby UPC » Sun Jan 05, 2025 11:18 am

Darcania wrote:The OP states that the region: and nation: buckets are not filters, so it seems like that's intentional (emphasis added by me):
Haku wrote:Buckets for viewing the activity of specific nations or regions can be done using the `nation:nation_name` or `region:region_name` syntax. Note that this is not a filter.

Appreciate that clarification, obviously my reading comprehension needs work! With that said, I still find it odd that if I subscribe to a regional bucket, I don't see endorsements, issues answered, etc within that region.
The Words of Radiance of UPC
Delegate of Europeia

(he/they)
Visit Europeia | Join Our Discord | Apply For Citizenship

User avatar
Elite
Attaché
 
Posts: 86
Founded: Oct 19, 2011
Liberal Democratic Socialists

Postby Elite » Sat Jan 11, 2025 12:31 pm

Was the reports page taxing on the server? I often used it to coastwatch during update, without it I fear that's no longer possible. It's kinda the death of old fashioned defending unless stealth raiders use a trigger long enough to show up on the activity page.
Knight of TITO
(views are my own etc. etc.)

they/them or he/him

User avatar
United Calanworie
Technical Moderator
 
Posts: 5193
Founded: Dec 12, 2018
Democratic Socialists

Postby United Calanworie » Sat Jan 11, 2025 3:50 pm

Elite wrote:Was the reports page taxing on the server? I often used it to coastwatch during update, without it I fear that's no longer possible. It's kinda the death of old fashioned defending unless stealth raiders use a trigger long enough to show up on the activity page.

Yeah it’s substantially more taxing on the server than the activity feed. We’re going to rework the feed to use the same SSE logic though instead of polling occasionally to refresh, so it’ll be realtime as well.
@queerlyfe | She/Her/Hers
Getting Help Request (GHR) | One Stop Rules Shop (OSRS) | Routine Actions thread | NS Announcements Discord
Script Rules | API Documentation | Approved Image Hosts | How Bots are Regulated | NS Coders Discord

"...against all enemies, foreign and domestic..."
You are such a crybaby [...] all you do is lock threads and be a bitch to people, nobody likes you, you aren’t cool, you lock every thread for stupid reasons, often times not giving a reason, [...] all you do is sit on your computer all day on NationStates, locking threads at a rate 5x higher than any other mod [...] stop trying so hard to impress people, literally nobody like you.
Have a good day

User avatar
Haku
Technical Moderator
 
Posts: 284
Founded: Jan 02, 2018
Corporate Police State

Postby Haku » Mon Jan 13, 2025 6:33 pm

We have now implemented the "views" filter as part of this endpoint.

Format:
Code: Select all
/api/bucket1+bucket2/bucket3+bucket4


In this case, you will be sent events that are in "bucket1" or "bucket2" only if those events also have "bucket3" or "bucket4".
Example:
Code: Select all
/api/move/region:the_north_pacific


If you don't want any views, requests using the old `/api/bucket1+bucket2` format will still work.

This has not yet been documented.

User avatar
Haku
Technical Moderator
 
Posts: 284
Founded: Jan 02, 2018
Corporate Police State

Postby Haku » Mon Jan 13, 2025 7:24 pm

UPC wrote:
Darcania wrote:The OP states that the region: and nation: buckets are not filters, so it seems like that's intentional (emphasis added by me):

Appreciate that clarification, obviously my reading comprehension needs work! With that said, I still find it odd that if I subscribe to a regional bucket, I don't see endorsements, issues answered, etc within that region.

There was a discrepancy with how we handled the region bucket in the happenings feed and how we handled it with SSE.

This has now been changed: endorsements, issue answering, etc will have the region:{region} bucket sent with them.
Last edited by Haku on Mon Jan 13, 2025 7:26 pm, edited 1 time in total.

User avatar
Darcania
Envoy
 
Posts: 214
Founded: Dec 29, 2014
Left-wing Utopia

Postby Darcania » Thu Jan 23, 2025 9:25 pm

It looks like custom fields aren't filled in server-sent events despite being filled in the happenings shard, e.g.:

Code: Select all
Following new legislation in @@new_yeetusia@@, gossip magazines have pictures of [[LEADER]] sunbathing on the beach with political rivals

vs

Code: Select all
<TEXT>Following new legislation in @@new_yeetusia@@, gossip magazines have pictures of Minister-Regent Calan XI sunbathing on the beach with political rivals.</TEXT>


also the SSE version is missing the fullstop at the end but that's a minor thing that definitely doesn't bother me
Last edited by Darcania on Thu Jan 23, 2025 9:30 pm, edited 1 time in total.

User avatar
Dhornaper
Lobbyist
 
Posts: 15
Founded: Jul 10, 2023
Left-Leaning College State

Postby Dhornaper » Fri Jan 24, 2025 2:31 am

The Yeetusa wrote:With the SSE endpoint's data being in JSON, does this mean the rest of the API eventually be moving away from XML in favor of JSON?


This is something I would also like to know. It would require a rewrite of a lot of my existing code.
Vussul/Dhornaper

Sultan bar Salatin-e Namak

User avatar
United Calanworie
Technical Moderator
 
Posts: 5193
Founded: Dec 12, 2018
Democratic Socialists

Postby United Calanworie » Fri Jan 24, 2025 3:36 pm

The Yeetusa wrote:With the SSE endpoint's data being in JSON, does this mean the rest of the API eventually be moving away from XML in favor of JSON?

Eventually is doing a lot of heavy lifting here, but that is a downstream goal yes.
@queerlyfe | She/Her/Hers
Getting Help Request (GHR) | One Stop Rules Shop (OSRS) | Routine Actions thread | NS Announcements Discord
Script Rules | API Documentation | Approved Image Hosts | How Bots are Regulated | NS Coders Discord

"...against all enemies, foreign and domestic..."
You are such a crybaby [...] all you do is lock threads and be a bitch to people, nobody likes you, you aren’t cool, you lock every thread for stupid reasons, often times not giving a reason, [...] all you do is sit on your computer all day on NationStates, locking threads at a rate 5x higher than any other mod [...] stop trying so hard to impress people, literally nobody like you.
Have a good day


Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: No registered users

Advertisement

Remove ads