how to deal with responses containing unicode in Kitura (swift)

56 Views Asked by At

I have a route ("/states"):

func initializeCodableRoutes(app: App) {
    app.router.get("/states", handler: app.getStatesHandler)
}

here is the corresponding handler (Codable handler):

extension App {
    func getStatesHandler(completion: ([State], RequestError?) -> Void) {
        let result = [State(id: 1, name: "تهران"),
                      State(id: 2, name: "آذربایجان شرقی"),
                      State(id: 3, name: "کرمان"),
                      State(id: 4, name: "آذربایجان غربی"),
                      State(id: 5, name: "اردبیل"),
                      State(id: 6, name: "اصفهان"),
                      State(id: 7, name: "البرز"),
                      State(id: 8, name: "ایلام"),
                      State(id: 9, name: "بوشهر"),
                      State(id: 10, name: "چهارمحال و بختیاری"),
                      State(id: 11, name: "خراسان جنوبی"),
                      State(id: 12, name: "خراسان رضوی")]
        completion(result, nil)
    }
}

and this is the code of State struct for more clarity:

struct State: Codable {
    let id: Int
    let name: String
}

when I run my server and try the {baseurl}/states in the browser, I get response like this:

[{"id":1,"name":"تهران"},{"id":2,"name":"آذربایجان شرقی"},{"id":3,"name":"کرمان"},{"id":4,"name":"آذربایجان غربی"},{"id":5,"name":"اردبیل"},{"id":6,"name":"اصÙهان"},{"id":7,"name":"البرز"},{"id":8,"name":"ایلام"},{"id":9,"name":"بوشهر"},{"id":10,"name":"چهارمحال Ùˆ بختیاری"},{"id":11,"name":"خراسان جنوبی"},{"id":12,"name":"خراسان رضوی"},{"id":13,"name":"Test"},{"id":14,"name":"تست"}]

how can I get the correct unicode response?

1

There are 1 best solutions below

0
Jafar Khoshtabiat On

I tried several browsers and saw that for example, firefox shows the correct unicode response(while safari not), so I understood that the problem sits in the decoding side of the client. server-side code works good enough.